【发布时间】:2017-09-20 15:52:30
【问题描述】:
以下场景在 javascript 中非常简单,但在 Angular 中运行时遇到了一些问题。
我有一个像这样的数组:
array a = ( "id" = 0, name = random(), column = 1, 2 or 3, blockrow= 1, 2 or 3)
使用 ngFor,我现在尝试创建一个网格,其中所有元素在此列中的列和块中分开。所以我当前的代码(有效但令人讨厌)。
<div *ngFor="let a of a">
<template [ngIf]="a.column=='1'">
<div *ngFor="let b of a">
<template [ngIf]="b.blockrow=='1'">
Block 1 in column 1{{b.name}}
</template>
</div>
<div *ngFor="let b of a">
<template [ngIf]="b.blockrow=='2'">
Block 2 in column 1{{b.name}}
</template>
</div>
<div *ngFor="let b of a">
<template [ngIf]="b.blockrow=='3'">
Block 3 in column 1{{b.name}}
</template>
</div>
</template>
</div>
我为每一列运行类似的东西。这意味着我在同一个数组中循环了 12 次。有没有办法让它更漂亮?
【问题讨论】: