Skip to content

Instantly share code, notes, and snippets.

@BrianGenisio
Created September 19, 2013 10:00
Show Gist options
  • Save BrianGenisio/6621396 to your computer and use it in GitHub Desktop.
Save BrianGenisio/6621396 to your computer and use it in GitHub Desktop.
ng-if modified to not create a child scope. (note my-if)
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