I have the following ngSwitch:
Wrong
This cannot be achieved with angular's base directives, but if you like, you could write your own directive to implement this, and could already interface with the existing ngSwitch directive.
ngSwitchController has one property cases
which is a map. Every case key is prefixed with an !
and the default case is equal to ?
. Each case value is an object with two properties: transclude
and element
.
Warning: Unlike ngModelController, ngSwitchController is not published API, so it's subject to change.
Based off of the original ngSwitchWhenDirective, we can construct a multiswitchWhen, that will work with all existing ngSwitch, ngSwitchWhen, and ngSwitchDefault directives without conflict.
.directive('multiswitchWhen', function () {
return {
transclude: 'element',
priority: 800,
require: '^ngSwitch',
link: function(scope, element, attrs, ctrl, $transclude) {
var selectTransclude = { transclude: $transclude, element: element };
angular.forEach(attrs.multiswitchWhen.split('|'), function(switchWhen) {
ctrl.cases['!' + switchWhen] = (ctrl.cases['!' + switchWhen] || []);
ctrl.cases['!' + switchWhen].push(selectTransclude);
});
}
}
});
Example plunker: http://plnkr.co/edit/K9znnnFiVnKAgGccSlrQ?p=preview