有人知道我为什么要这么做吗?
错误 类型错误:_this.user_data.apply不是函数
试图用JSON文件的映射结果填充user_data时
user_data: any;
this.testService.getTestWithObservable()
.map( result => result.map( i => i.users.data) )
.subscribe(
res => {
this.user_data = [];
res.forEach(i => this.user_data(...i));
console.log(this.user_data);
}
);
}
JSON
[{
"id": 1,
"users": {
"user_id": 14,
"data": [{
"name": "James",
"age": 20
},
{
"name": "Damien",
"age": 25
}]
}
}
{
"id": 2,
"users": {
"user_id": 11,
"data": [{
"name": "James",
"age": 20
},
{
"name": "Damien",
"age": 25
}]
}
}]
我找不到与此错误/代码相关的任何内容
答案 0 :(得分:0)
已解决:
TS
res => {
this.user_data= res;
}
HTML
<div *ngFor="let data of user_data">
<div *ngFor="let x of data">
{{ x.name}}
</div>
</div>