Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs: multiple values in a ng-switch-when

I have the following ngSwitch:

<p ng-switch="status">     <span ng-switch-when="wrong|incorrect">        Wrong     </span>     <span ng-switch-default>        Correct     </span> </p> 

As you can see, I have the text Wrong for two options wrong and correct. I have tried (as you can see) to use the pipe |, but that doesn't work. Any suggestions ?

like image 823
Jeanluca Scaljeri Avatar asked Mar 24 '14 13:03

Jeanluca Scaljeri


People also ask

What is the use of NG switch and Ng switch when directives?

Definition and UsageThe ng-switch directive lets you hide/show HTML elements depending on an expression. Child elements with the ng-switch-when directive will be displayed if it gets a match, otherwise the element, and its children will be removed.

Which directive allows to conditionally swaps the contents of a section based upon matched value?

The ngSwitch directive is used to conditionally swap DOM structure on your template based on a scope expression.

What is ngSwitch in angular?

The [ngSwitch] directive on a container specifies an expression to match against. The expressions to match are provided by ngSwitchCase directives on views within the container. Every view that matches is rendered. If there are no matches, a view with the ngSwitchDefault directive is rendered.


1 Answers

For angular >=v1.5.10,

You can do it by adding ng-switch-when-separator="|" to ng-switch-when node. see example in documentation.

<span ng-switch-when="wrong|incorrect" ng-switch-when-separator="|"> 

see discussion here https://github.com/angular/angular.js/issues/3410 Note, based on my experience it doesn't work with numbers...yet?

like image 189
Chauskin Rodion Avatar answered Oct 06 '22 15:10

Chauskin Rodion