2 回答

TA貢獻1884條經(jīng)驗 獲得超4個贊
您可以使用以下方法來執(zhí)行此操作:
根據(jù)大小變量將數(shù)組轉(zhuǎn)換為二維數(shù)組。
現(xiàn)在在模板中迭代該數(shù)組。
.ts
newArr = []
size = 2; // change this as per your requirement
ngOnInit() {
while (this.arr.length) {
this.newArr.push(this.arr.splice(0, this.size)); // create 2D array
}
}
.html
<table>
<tbody>
<tr *ngFor="let outer of newArr">
<td *ngFor="let group of outer">{{group.Name}}</td>
</tr>
</tbody>
</table>

TA貢獻1809條經(jīng)驗 獲得超8個贊
基于size變量,您可以創(chuàng)建一個長度為 size 的數(shù)組,并使用另一個*ngFor包含該數(shù)組的數(shù)組來渲染列。
例子
成分
class MyComponent extend OnInit {
size = 4;
sizeArray = [];
ngOnInit() {
this.sizeArray = new Array(this.size)
}
}
模板
<tbody>
<tr *ngFor="let group of arr">
<td *ngFor="let index of sizeArray">
{{group.name}}
</td>
</tr>
</tbody>
- 2 回答
- 0 關(guān)注
- 144 瀏覽
添加回答
舉報