【发布时间】:2021-12-22 04:00:05
【问题描述】:
我的 Angular 项目中有这项服务
getOfertas(): Observable<Oferta[]> {
return this.http.get<Oferta[]>(`${this.urlWebAPI}/ofertas`)
.pipe(
tap(data=>console.log('OfertasService-get(): ', data)
),
catchError(this.handleError)
)
}
我在 Angular Component.ts 中使用的
ofertas:Oferta[]=[];
ngOnInit(): void {
this.dataService.getOfertas()
.pipe(
tap(item=>console.log(item))
)
.subscribe(
data=>{
this.ofertas=data;
this.ofertasOriginal=this.ofertas;
}
)
,err=>console.log(err),
()=>{};
}
}
我想在这个 Component.html 中的表格中查看结果
<div class='table-responsive'>
<table class='table'>
<thead>
<tr>
<th>Id</th>
<th>Id Presentada</th>
<th>Descripción</th>
<th>Organismo</th>
<th>Fª Presentación</th>
<th>Presupuesto</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let oferta of ofertas; let index=index">
<td>{{oferta.id}}</td>
<td>{{oferta.idPresentada}}</td>
<td>{{oferta.descripcion}}</td>
<td>{{oferta.id}}</td>
<td>{{oferta.fechaPresentacionFulcrum}}</td>
<td>{{oferta.id}}</td>
</tr>
</tbody>
</table>
</div>
但是我使用从 ASP.NEt Core Web API 获得的数据在控制台中得到了这个结果,但是显示了错误
在我的 Web API 中,我在调试时看到此结果返回。
即 Oferta 对象列表
但是在 Angular 中,我得到了一个奇怪的对象
{$id:
$values:[]
}
但如果我使用这个 ~$values 进行迭代,我仍然什么也看不到
<tr *ngFor="let oferta of ofertas.$values; let index=index">
如果我尝试分配这个
我想使用我的 ofertas 变量 ofertas:Oferta[]=[]
这里我有一个同样问题的例子; https://stackblitz.com/edit/angular-ivy-ymtnrw?file=src/app/app.component.html
有什么想法吗?
谢谢
【问题讨论】:
标签: angular asp.net-core asp.net-web-api