角度:按计数创建两列

时间:2019-03-25 15:33:12

标签: angular angular-ng-if

下面的代码基于偶数和奇数创建两列。我将如何更改,而不是在第1列中显示前8个结果,在第2列中显示其余的结果,而不是偶数和奇数?

<div *ngFor="let year of userYear; let i = index">
     <div *ngIf='i%2 === 0' class="float-left left-column push-left"><span>{{year}}</span></div>
     <div *ngIf='i%2 !== 0' class="float-left right-column"><span>{{year}}</span></div>
</div> 

1 个答案:

答案 0 :(得分:1)

只需将i%2 === 0更改为i < 8,将i%2 !== 0更改为i >= 8

<div *ngFor="let year of userYear; let i = index">
     <div *ngIf='i < 8' class="float-left left-column push-left"><span>{{year}}</span></div>
     <div *ngIf='i >= 8' class="float-left right-column"><span>{{year}}</span></div>
</div>