【发布时间】:2021-08-16 01:03:20
【问题描述】:
我有一个项目需要过滤以显示它是否可用。我正在使用切换,因为它必须是动态的。问题是我有一个函数调用,它向我发送了一个标题数组,这些标题可以通过切换显示出来。
<ion-item *ngFor="let serVivo of seresVivos" id="items">
<div *ngFor="let available of availables">
<ng-template *ngIf="available === serVivo.title;then showBlock; else notShowBlock">
</ng-template>
<ng-template #showBlock>
<ion-toggle (ionChange)="change(serVivo.title, $event)" checked ></ion-toggle>
</ng-template>
<ng-template #notShowBlock>
<ion-toggle (ionChange)="change(serVivo.title, $event)" ></ion-toggle>
</ng-template>
</div>
</ion-item>
因为它只能匹配一次,所以当标题匹配数组的一项时,它会正确显示切换。然而,由于不匹配的都是其余的,所以它创建了与数组可用的相同的项目。 Result with the actual code.The result only creating the true toggles
【问题讨论】:
标签: angular ionic-framework ngfor angular-ng-if ng-template