[英]Property 'id' does not exist on type 'never'
I am trying to display an API using *ngFor in frontend.我正在尝试在前端使用 *ngFor 显示 API。 But I am getting this error.
但我收到了这个错误。 "Property 'id' does not exist on type 'never'."
“‘从不’类型上不存在属性‘id’。” data is coming in console.
数据进入控制台。 My ts code,
我的ts代码,
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.