在Range7应用程序中,我试图从API调用中获取表格数据,并将相同的数据分配给HTML元素。在这里添加了以下代码。我能够将数据记录在调用代码的内括号中,但这些数据是不可用的。我无法将它分配给任何HTML元素。
打字稿班:
export class IBiodatas{
CompanyId:number;
EmpCode: string;
ImageURL: string;
Name: string;
UserId : number;
}打字本服务电话:
getDetail(userName):Observable<IBiodatas[]>{
return this.http.get<IBiodatas[]>(this.API_URL + userName,this.httpOptions).pipe(
catchError(this.handleError('getDetail',[]))
)
}打字本组件代码:
heroes: IBiodatas[];
getDetail(): void {
this.biodataService.getDetail('?userName=Santosh')
.subscribe(
data=> {
this.heroes = Array.of(data.data.Table[0]);//Error: Property 'data' does not exist on type 'IBiodatas[]'.
console.log('456456',this.heroes);
},
);
}从API收到的数据:
{
"APIExecutionTime":"0 sec(s) to execute the function",
"data":{
"Table":[{
"UserId":654,
"ImageURL":"654.png",
"Name":"Santosh Pal",
"CompanyId":78,"EmpCode":"987"
}]},
"httpStatusCode":200,
"msg":"OK",
"IsValid":true
}
how to get data.Table[0] and assign to class propertysrc/app/app.Component.ts(30,41)中的错误:错误TS2339:属性'IBiodatas[]‘在’IBiodatas[]‘类型中不存在。
发布于 2019-12-30 07:46:25
getDetail(){
this.biodataService.getDetail('?userName=Santosh').subscribe
(data =>{
this.heroes1 = Array.of(data)
this.heroes = Array.of(this.heroes1[0].data.Table[0]);
});}
发布于 2019-12-26 11:58:07
你可以这样做:
<table>
<tr>
<th>UserId</th>
<th>Name</th>
</tr>
<tr *ngFor="let data of data.Table">
<td>{{data.UserId}}</td>
<td>{{data.Name}}</td>
</tr>
</table>发布于 2019-12-26 12:05:46
尝试如下:
this.data = JSON.stringify(res);而不是只使用this.data = res.data.table
<table>
<tr>
<th>UserId</th>
<th>Name</th>
</tr>
<tr *ngFor="let d of data">
<td>{{d.UserId}}</td>
<td>{{d.Name}}</td>
</tr>
</table>https://stackoverflow.com/questions/59488048
复制相似问题