Ser*_*pov 4 angular2-template angular
我有两个字符串数组,我想迭代其中一个取决于条件.如何避免代码重复?现在*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>
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?
<tr>
<td *ngFor="let field of (condition ? secondArray : firstArray)">{{field}}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1671 次 |
| 最近记录: |