Last active
January 4, 2016 21:19
-
-
Save stinoga/8679872 to your computer and use it in GitHub Desktop.
Angular Lazy Load
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lazy load directive, taken from http://slid.es/djsmith/deep-dive-into-custom-directives | |
directive('myLazyLoad', function() { | |
return { | |
transclude: 'element', | |
priority: 1200, // changed needed for 1.2 | |
terminal: true, | |
restrict: 'A', | |
compile: function(element, attr, linker) { | |
return function (scope, iterStartElement, attr) { | |
var hasBeenShown = false; | |
var unwatchFn = scope.$watch(attr.myLazyLoad, function(value){ | |
if (value && !hasBeenShown) { | |
hasBeenShown = true; | |
linker(scope, function (clone) { | |
iterStartElement.after(clone); | |
}); | |
unwatchFn(); | |
} | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment