[英]ngFor inside ngFor with two components
I have this: 我有这个:
<div *ngFor=" let item of data " >
// some details
<app-child [user]="item"></app-child>
</div>
and in my child: 在我的孩子中:
<div *ngFor=" let element of user " >
// some details
<a> {{element.name}} </a>
<div>
I can't read anything in element, what is the right way to achieve this? 我看不到任何内容,实现此目标的正确方法是什么?
EDIT 编辑
parent component.ts: 父component.ts:
public data: any = [];
//API CALLS
this.result.forEach(item => {
this.data.push(item);
});
this is my console.log(data)
这是我的console.log(data)
and inside it there is an array called (comments) and I want to ngFor it and read the comments inside it, In conclusion I want to ngFor my posts and each post ngFor its comments. 在其中有一个名为(comments)的数组,我想对其进行ngFor并阅读其中的注释,最后,我要对自己的帖子和每个帖子ngFor进行评论。
Make sure you are taking the user array in your child-component as input 确保您将子组件中的用户数组作为输入
@Input() user : User;
EDIT 编辑
It seems your child component is getting an object not an array, so don't use ngFor, directly use 看来您的子组件正在获取对象而不是数组,所以不要使用ngFor,请直接使用
<div >
<a> {{user.name}} </a>
<div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.