Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.