我正在尝试使用ngFor填充分块结果
<div *ngFor="let item of states; let i = index">
<ul>
<li ngFor="let state of item">{{item}}</li>
</ul>
</div>
分块结果将转换为字符串
如果我尝试填充状态
<div *ngFor="let item of states; let i = index">
<ul>
<li ngFor="let state of item">{{state}}</li>
</ul>
</div>
我得到一个空白输出。
如果在第二次ngFor之前使用*
<div *ngFor="let item of states; let i = index">
<ul>
<li *ngFor="let state of item">{{state}}</li>
</ul>
</div>
后面收到错误消息
我如何组合并填充值?
编辑-1&amp; 2
编辑3 这是我的html输出。如果我使用
,数据将填充为字符串<div class="split-by-4">
<div *ngFor="let item of states; let i = index">
<ul>
<li ngFor="let state of item[i]">{{item}}</li>
</ul>
</div>
</div>
工作回答(实际上是我的错误)
{
$("#cities-with-state-modal").modal('open');
this.chunkStates();
}
chunkStates(){
this.states = _.cloneDeep(this.backup.states); // this.states is loading and its giving as string before the data got chunked.
let chunkSize = _.toInteger(this.states.length/4);
this.statesChunk = _.chunk(this.states, chunkSize);
}
HTML
<div class="split-by-4" *ngIf="statesChunk && statesChunk.length">
<div *ngFor="let item of statesChunk; let i = index">
<ul>
<li *ngFor="let state of item">{{state.name}}</li>
</ul>
</div>
</div>
答案 0 :(得分:1)
你有一个错字:
你忘记了<li ngFor
中的星号。 (因此错误)。
另外 -
您正在迭代对象的数组数组。所以你最后需要一个道具。
区别:见{{state.MyStateProperty}}
<div *ngFor="let item of states; let i = index">
<ul>
<li *ngFor="let state of item">{{state.MyStateProperty}}</li>
</ul>
</div>
Here's a basic working plnkr representing your nested structure.