Created
April 24, 2014 18:35
-
-
Save 0xBADC0FFEE/11264790 to your computer and use it in GitHub Desktop.
Lazy loading expensive DOM
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
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