gpt4 book ai didi

angular - *ngFor 中的条件

转载 作者:太空狗 更新时间:2023-10-29 17:46:53 24 4
gpt4 key购买 nike

我有两个字符串数组,我想根据条件循环访问其中一个。如何避免代码重复?现在 *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>

关于angular - *ngFor 中的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39485343/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com