【发布时间】:2017-09-09 00:25:13
【问题描述】:
我基本上是在尝试计算 ngFor 指令概述的列表数量。我已经遵循了很多解决方案来解决我的问题,但这并不成功。下面是我的代码,我得到了错误,没有定义父级。
管道
@Pipe({name: 'keys'})
export class KeysPipe implements PipeTransform {
parent : string;
transform(value) : any {
let keys = [];
if(value) {
this.parent = value;
return Object.keys(value)
}
}
}
html
<div *ngFor="let game of games">
<div *ngFor="let key of game| keys">
<li> {{game[key].type}} </li>
{{ game[key].location}}
Count: {{game.parent.length}}
</div>
</div>
输出
mario - germany
kart - london
rings - france
total number of items = 3
【问题讨论】: