Last active
August 29, 2015 14:12
-
-
Save mallowigi/835bf1964b7f7d944d58 to your computer and use it in GitHub Desktop.
angular ngswitchwhen decorator for dynamic usage
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
.config(function ($provide) { | |
'use strict'; | |
$provide.decorator('ngSwitchWhenDirective', function ($delegate) { | |
angular.forEach($delegate, function (ngSwitchWhen) { | |
// override default compile method since it has already closed over | |
// the directive definition's link function | |
ngSwitchWhen.compile = function () { | |
return function (scope, element, attrs, ctrl, $transclude) { | |
var whenCase = scope.$eval(attrs.ngSwitchWhen); | |
ctrl.cases['!' + whenCase] = (ctrl.cases['!' + whenCase] || []); | |
ctrl.cases['!' + whenCase].push({transclude: $transclude, element: element}); | |
}; | |
}; | |
}); | |
return $delegate; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment