Two switch case values in angular
angular
Solution
(Un)fortunately you can‘t; the `ngSwitch` is quite “dumb” if you look at the source code: it‘s just a `===` between the case value and the switch value. You have two options, but both of them are far from great.
Option 1 is using the directive `*ngSwitchDefault`, but this will only work if all your multiple cases are FORM 1:
<div [ngSwitch]="data.type">
<div *ngSwitchDefault>FORM 1</div>
<div *ngSwitchCase="'range'">FORM 2</div>
</div>
The other option, which is quite verbose, is doing something like this:
<div [ngSwitch]="data.type">
<div *ngSwitchCase="data.type === 'multi-choice' || data.type === 'singe-choice' ? data.type : '' ">FORM 1</div>
<div *ngSwitchCase="'range'">FORM 2</div>
</div>
Problem
In php and java we can do ``` case 1: case 2: echo "something"; ``` so that when the value is 1 or 2 "something" will be printed on the screen, i am building an angular application i am doing something like the below ``` <div [ngSwitch]="data.type"> <div *ngSwitchCase="'multi-choice'">FORM 1</div> <div *ngSwitchCase="'singe-choice'">FORM 1</div> <div *ngSwitchCase="'range'">FORM 2</div> </div> ``` The form which is used for single choice can be used for mutiple choice , but i tried something like below to make it more organisable ``` <div [ngSwitch]="data.type"> <div *ngSwitchCase="'multi-choice' || 'singe-choice'">FORM 1</div> </div> ``` My bad luck it didnt work, can anyone suggest the better way to do this.