Angular 简单指令 n​​gIf

Angular Simple Directive ngIf

我不知道如何在 angular 中写下我的条件,我也找不到合适的例子。

如何收听我的 material 选择?

如何编写 ngIf 条件?

{{referentielToDisplay.speSS}} 与我的一个 toppingList 具有相等的值,我想写:

如果 ReferentielToDisplay。 speSS 等于在 material 选择中选择的项目,因此:显示此卡片

*ngIf="referentielToDisplay.speSS === topping"

Component.html

<mat-form-field style="width:100%" appearance="outline">
  <mat-label>Sélectionner une spécialité</mat-label>
  <mat-select placeholder="Toppings" [formControl]="toppings" multiple="true" >
    <mat-option *ngFor="let topping of toppingList" [value]="topping" >{{topping}}</mat-option>
  </mat-select>
</mat-form-field>

<div  *ngFor="let referentielToDisplay  of referentielsToDisplay | async" >
<mat-card *ngIf="referentielToDisplay.speSS === topping">
{{referentielToDisplay.nomSS}}
</mat-card>
</div>

Component.ts

toppings = new FormControl( );
toppingList: string[] = ['Multi-spécialité','Hématologie', 'Neurologie', 'Urologie', 'Digestif', 'Endocrinologie',  'Pneumologie', 'ORL','Dermatologie', 'Sein-Gynecologie'];

您可以尝试 indexOf 条件:

<mat-card *ngIf="toppingList.indexOf(referentielToDisplay.speSS) > -1">
  {{referentielToDisplay.nomSS}}
</mat-card>

<mat-card *ngIf="toppingList.includes(referentielToDisplay.speSS)">
  {{referentielToDisplay.nomSS}}
</mat-card>

Ìt 检查列表是否包含您的值 referentielToDisplay.speSS

*ngIf="toppings.value.includes(referentielToDisplay.speSS)" 

这不是完全的解决方案,但它是方法!!