【发布时间】:2021-07-03 02:36:08
【问题描述】:
我有一个获取请求的响应
{
"status": "true",
"Products": [
{
"productid": 1,
"addedby": 0,
"name": "Jackfruit",
"slug": "jackfruit",
etc....}]}
compoent.ts 为
i = 0;
name = "";
constructor(private httpClient: HttpClient) { }
ngOnInit() {
return this.httpClient.get(this.apiURL).subscribe((result: any)=>{
if(result.status == "false" )
console.log("result",result.status)
else
{
this.name = result.Products[this.i].name;
for(this.i ;this.i < result.Products.length ;this.i++)
{
console.log( result.Products[this.i].productid +" " +result.Products[this.i].name )
}
}
})}
我需要在 component.html 中显示这些名称..我试过 {{name}} 但它只显示第一个产品名称,即菠萝蜜..如果我在 for 循环中给出 this.name = result.Products[this.i].name;,它显示最后产品名称
【问题讨论】:
标签: angular data-binding