*ngFor中的条件

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)

有没有更好的办法?

Gün*_*uer 8

<tr>
    <td *ngFor="let field of (condition ? secondArray : firstArray)">{{field}}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)