Salman Laei
Salman Laei

Reputation: 61

Two values in one switch case in angularjs

Like what we have in C# (mutliple values with the same output)

switch (CommandId)
                {
                    case 1:
                    case 2:
                      .
                      .
                      .
                        {
                            return "test";
                        }
                 }

I want to have 2 or more cases with the same output in angularjs

  <div ng-switch="ctrl.Step">
     <button class="md-raised md-primary" ng-switch-when="1" ng-click="ctrl.save()">
              Save
     </button>
     <button class="md-raised md-primary" ng-switch-when="2" ng-click="ctrl.save()">
              Save
     </button>
 </div>

What is the syntax for such code?

Upvotes: 1

Views: 164

Answers (1)

pbachman
pbachman

Reputation: 1059

you can do it with the ng-switch-when-separator, please look at the doc.

<div ng-switch="ctrl.Step">
     <button class="md-raised md-primary" ng-switch-when="1|2" ng-switch-when-separator="|" ng-click="ctrl.save()">
              Save
     </button>
 </div>

Upvotes: 1

Related Questions