角度 – * ngFor中的条件
发布时间:2020-12-17 17:22:18 所属栏目:安全 来源:网络整理
导读:我有两个字符串数组,我想迭代其中一个取决于条件.如何避免代码重复?现在* ngIf现在: tr *ngIf="!condition" td *ngFor="let field of firstArray"{{field}}/td/trtr *ngIf="condition" td *ngFor="let field of secondArray"{{field}}/td/tr 有没有更好的
我有两个字符串数组,我想迭代其中一个取决于条件.如何避免代码重复?现在* ngIf现在:
<tr *ngIf="!condition"> <td *ngFor="let field of firstArray">{{field}}</td> </tr> <tr *ngIf="condition"> <td *ngFor="let field of secondArray">{{field}}</td> </tr> 有没有更好的办法? 解决方法<tr> <td *ngFor="let field of (condition ? secondArray : firstArray)">{{field}}</td> </tr> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |