Jeanluca Scaljeri Jeanluca Scaljeri - 3 months ago 42
AngularJS Question

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 ?

Answer

You can't have multiple conditions with a single ng-switch-when.

One alternative is to use an ng-if, but in the case of error handling, I prefer to populate an error variable on the scope in the controller, and use ng-show=error.