I am trying to display an API using *ngFor in frontend. But I am getting this error. "Property 'id' does not exist on type 'never'." data is coming in console. My ts code,
posts = [] //problem lies here I guess
constructor(private user:UsersService)
{
this.user.getData().subscribe(data=>{
console.warn(data); // uptill here code works
this.posts = data; // and here
})
}
my frontend code,
<table border="1">
<tr>
<td>Id</td>
<td>Title</td>
<td>User Id</td>
</tr>
<tr *ngFor="let post of posts">
<td>{{post.id}}</td>
<td>Title</td>
<td>User Id</td>
</tr>
Thanks in advance
try following code. try to declare posts as any type
posts:any;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.