我基本上試圖計數,然後由ngFor指令列出的列表數。我遵循了很多解決方案來解決我的問題,但這不是成功的。下面是我的代碼,我得到的錯誤,父母沒有定義。使用ngFor計數項目與管道 - 角2
管
@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
我想顯示的項目總數。沒有列出項目 – XamarinDevil
旁邊的數字,你可以給出一個例子json和期望的輸出。 '顯示的項目總數可以使用games.length * ..'本身計算 – Aravind
請看看現在編輯的問題並看看輸出 – XamarinDevil