当我尝试在 Angular 中使用 ngfor 在 html 模板上显示来自 get api 的数据时,会出现此错误
错误错误:找不到类型为“对象”的不同支持对象“[对象对象]”。NgFor 仅支持绑定到 Iterables,例如 Arrays。
这是我的 bankComponent.ts 文件
getSearchBankAPI(postData : Create , postForm : NgForm){
this._newApiService.getSearchBank(
postData.address,
postData.bankId,
postData.bankName,
postData.branch,
postData.ifscCode,
postData.passBookNo
)
console.log("Search Customer API Called!!");
postForm.reset();
localStorage.setItem("bankIFSCvalue",this.bankvalue);
console.log(localStorage.getItem("bankIFSCvalue"))
this.getBankById();
}
public getBankById(){
return this.http.get('http://localhost:9900/api/v1/bank/' + localStorage.getItem("BankId"))
.subscribe((responseData)=>
{
this.response = JSON.parse(JSON.stringify(responseData));
console.log("Bank name is :" + this.response.body.bankName)
console.log(this.response)
});
}
}
在这里,我从 getSearchBankAPI() 方法调用 getBankById() get API,我想在模板上显示 getBankId() get API 的结果。
这是我的模板代码
<thead>
<tr>
<th scope="col">Bank Name</th>
<th scope="col">Branch</th>
<th scope="col">IFSCCode</th>
</tr>
<tr *ngFor="let e of response">
<th scope="col">{{e.bankName}}</th>
<th scope="col">{{e.branch}}</th>
<th scope="col">{{e.ifscCode}}</th>
</tr>
</thead>
</table>