Last active
December 5, 2016 08:14
-
-
Save accolver/4987806b026fd8a03568 to your computer and use it in GitHub Desktop.
ng-lazy-show
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
'use strict'; | |
var ngLazyShowDirective = ['$animate', function ($animate) { | |
return { | |
multiElement: true, | |
transclude: 'element', | |
priority: 600, | |
terminal: true, | |
restrict: 'A', | |
link: function ($scope, $element, $attr, $ctrl, $transclude) { | |
var loaded; | |
$scope.$watch($attr.ngLazyShow, function ngLazyShowWatchAction(value) { | |
if (loaded) { | |
$animate[value ? 'removeClass' : 'addClass']($element, 'ng-hide'); | |
} | |
else if (value) { | |
loaded = true; | |
$transclude(function (clone) { | |
clone[clone.length++] = document.createComment(' end ngLazyShow: ' + $attr.ngLazyShow + ' '); | |
$animate.enter(clone, $element.parent(), $element); | |
$element = clone; | |
}); | |
} | |
}); | |
} | |
}; | |
}]; | |
angular.module('yourModule').directive('ngLazyShow', ngLazyShowDirective); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using ng-lazy-show maybe you will lose scope because there is different behavior between ng-if and ng-show