How can I use ng-switch to satisfy multiple, same conditions?

后端 未结 3 1009
被撕碎了的回忆
被撕碎了的回忆 2021-01-23 09:14

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

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-23 09:48

    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

提交回复
热议问题