-2

My question duplicat at How to use *ngIf else in Angular?

2 Answers2

3

Wait it's simpler then that. In template:

<div *ngIf = "name == 'a'">if a</div>
<div *ngIf = "name == 'b'">if b</div>
<div *ngIf = "name == 'c'">if c</div>

edit

If you want to make it dynamic do *ngFor let name of names and do ngIf on {{name}}

<div *ngFor="let name of names">
<p *ngIf = "name == {{name}}">Your if</p>
</div> //something like this.
Swoox
  • 3,707
  • 2
  • 21
  • 32
2
if(name == 'a'){
  console.log("1");
} else if(name == 'b') { 
  console.log("2");
} else {
  console.log("other");
}

inline:

*ngIf="name == 'a' ? test('1') : name == 'b' ? test('2) : test('other)"

test is a function that you have to create... or do something else..

Carsten
  • 4,005
  • 21
  • 28