Skip to content

Instantly share code, notes, and snippets.

@mallowigi
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mallowigi/835bf1964b7f7d944d58 to your computer and use it in GitHub Desktop.
Save mallowigi/835bf1964b7f7d944d58 to your computer and use it in GitHub Desktop.
angular ngswitchwhen decorator for dynamic usage
.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