I want to create a piece of HTML with AngularJS based on the authentication status.
I use ng-switch
.
The issue is that I want to have multiple hits
Unfortunately the ng-switch directive only supports multiple matches since version 1.1.3 of AngularJS.
See the changelog and this commit as reference.
Someone overwrote the ngSwitchWhen Directive to include the option to allow || operators, you can find the original response here: http://docs.angularjs.org/api/ng.directive:ngSwitch by angabriel
config(function($routeProvider, $provide) {
/**
* overwrite angular's directive ngSwitchWhen
* can handle ng-switch-when="value1 || value2 || value3"
*/
$provide.decorator('ngSwitchWhenDirective', function($delegate) {
$delegate[0].compile = function(element, attrs, transclude) {
return function(scope, element, attr, ctrl) {
var subCases = [attrs.ngSwitchWhen];
if(attrs.ngSwitchWhen && attrs.ngSwitchWhen.length > 0 && attrs.ngSwitchWhen.indexOf('||') != -1) {
subCases = attrs.ngSwitchWhen.split('||');
}
var i=0;
var casee;
var len = subCases.length;
while(i<len) {
casee = $.trim(subCases[i++]);
ctrl.cases['!' + casee] = (ctrl.cases['!' + casee] || []);
ctrl.cases['!' + casee].push({ transclude: transclude, element: element });
}
}
}
return $delegate;
});
});
Angular 1.1.5 supports ng-if
. You can look at that. Then you can have independent conditions.