[英]ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. Getting this in get API
This Error is coming when I am trying to show the data from an get api on html template using ngfor in angular当我尝试使用 angular 中的 ngfor 在 html 模板上显示来自 get api 的数据时,出现此错误
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'.错误 错误:找不到支持“对象”类型的 object“[对象对象]”的不同。 NgFor only supports binding to Iterables such as Arrays.
NgFor 仅支持绑定到 Iterables,例如 Arrays。
This is my bankComponent.ts file这是我的 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)
});
}
}
Here I am calling the getBankById() get API from getSearchBankAPI() method and I want to display the result of getBankId() get API on the template.这里我调用 getBankById() get API from getSearchBankAPI() 方法,我想在模板上显示 getBankId() get API 的结果。
This is my template code这是我的模板代码
<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>
Is the answer to use...答案是用...
<tr *ngFor="let e of response.body">
instead of代替
<tr *ngFor="let e of response">
? ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.