Created
September 19, 2013 10:00
-
-
Save BrianGenisio/6621396 to your computer and use it in GitHub Desktop.
ng-if modified to not create a child scope. (note my-if)
This file contains hidden or 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
app.directive('myIf', ['$animate', function($animate) { | |
return { | |
transclude: 'element', | |
priority: 1000, | |
terminal: true, | |
restrict: 'A', | |
compile: function (element, attr, transclude) { | |
return function ($scope, $element, $attr) { | |
var childElement, childScope; | |
$scope.$watch($attr.myIf, function ngIfWatchAction(value) { | |
if (childElement) { | |
$animate.leave(childElement); | |
childElement = undefined; | |
} | |
if (toBoolean(value)) { | |
transclude($scope, function (clone) { | |
childElement = clone; | |
$animate.enter(clone, $element.parent(), $element); | |
}); | |
} | |
}); | |
} | |
} | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment