[英]ngFor inside ngFor with two components
我有這個:
<div *ngFor=" let item of data " >
// some details
<app-child [user]="item"></app-child>
</div>
在我的孩子中:
<div *ngFor=" let element of user " >
// some details
<a> {{element.name}} </a>
<div>
我看不到任何內容,實現此目標的正確方法是什么?
編輯
父component.ts:
public data: any = [];
//API CALLS
this.result.forEach(item => {
this.data.push(item);
});
在其中有一個名為(comments)的數組,我想對其進行ngFor並閱讀其中的注釋,最后,我要對自己的帖子和每個帖子ngFor進行評論。
確保您將子組件中的用戶數組作為輸入
@Input() user : User;
編輯
看來您的子組件正在獲取對象而不是數組,所以不要使用ngFor,請直接使用
<div >
<a> {{user.name}} </a>
<div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.