*ngFor="let item of fruits; let i = index"
// html file <ul> <li *ngFor="let item of fruits; let i = index"> {{i}} - {{item}} </li> </ul> // ts file fruits = ["Mango", "Banana", "Sitafal"];
0 - Mango 1 - Banana 2 - Sitafal
// If you want to check only value then use bellow syntax *ngIf="item == 'Mango'" // If you want to check strict with data type and value the use bellow syntax *ngIf="item === 'Mango'"
// html file <ul> <li *ngFor="let item of fruits; let i = index"> <ng-container *ngIf="item != 'Mango'"> {{i}} - {{item}} </ng-container> </li> </ul> // ts file fruits = ["Mango", "Banana", "Sitafal"];
1 - Banana 2 - Sitafal
@Component({ selector: 'ngswitch-example', template: `<h4>NgSwitch</h4> <ul *ngFor="let person of people" [ngSwitch]="person.country"> (1) <li *ngSwitchCase="'UK'" (2) class="text-success">{{ person.name }} ({{ person.country }}) </li> <li *ngSwitchCase="'USA'" class="text-primary">{{ person.name }} ({{ person.country }}) </li> <li *ngSwitchCase="'HK'" class="text-danger">{{ person.name }} ({{ person.country }}) </li> <li *ngSwitchDefault (3) class="text-warning">{{ person.name }} ({{ person.country }}) </li> </ul>` }) class NgSwitchExampleComponent { people: any[] = [ { "name": "Douglas Pace", "age": 35, "country": 'MARS' }, { "name": "Mcleod Mueller", "age": 32, "country": 'USA' }, { "name": "Day Meyers", "age": 21, "country": 'HK' }, { "name": "Aguirre Ellis", "age": 34, "country": 'UK' }, { "name": "Cook Tyson", "age": 32, "country": 'USA' } ]; }