Skip to content

Instantly share code, notes, and snippets.

@stinoga
Last active January 4, 2016 21:19
Show Gist options
  • Save stinoga/8679872 to your computer and use it in GitHub Desktop.
Save stinoga/8679872 to your computer and use it in GitHub Desktop.
Angular Lazy Load
// 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