Skip to content

Instantly share code, notes, and snippets.

@0xBADC0FFEE
Created April 24, 2014 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xBADC0FFEE/11264790 to your computer and use it in GitHub Desktop.
Save 0xBADC0FFEE/11264790 to your computer and use it in GitHub Desktop.
Lazy loading expensive DOM
directive('lazyHtml', function() {
return {
transclude: 'element',
priority: 1200,
terminal: true,
restrict: 'A',
compile: function(element, attr, linker) {
return function ($scope, $element, $attr) {
var visible = false;
var stopWatching = $scope.$watch($attr.lazyHtml, function(value){
if (value && !visible) {
visible = true;
linker($scope, function (clone) {
$element.after(clone);
});
stopWatching();
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment