我有一個使用 Python 后端和 MongoDB 的 Angular 應用程式。我正在嘗試通過以下網址獲得一條評論:
http://localhost:5000/api/v1.0/players/' id '/reviews/' rid
在我的web.service.ts我有以下功能:
getReview(id: any, rid: any) {
return this.http.get('http://localhost:5000/api/v1.0/players/' id '/reviews/' rid);
}
在我的review.component.ts我有這個:
ngOnInit() {
this.player = this.webService.getPlayer(this.route.snapshot.params['id']);
this.player_review = this.webService.getReview(this.route.snapshot.params['id'], this.route.snapshot.params['rid']);
}
this.player獲取所有玩家資料,this.player_review并假設帶回單個評論。
該this.player作業正常,但我得到這個錯誤this.player_review:
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
這是網址: http://localhost:4200/players/6194f873570f9ac9f081763e/reviews/61cde0f8daa68a9b80b3f3ad
這是它作業的郵遞員螢屏截圖:

為什么會發生此錯誤?
uj5u.com熱心網友回復:
getReview 方法回傳物件而不是陣列。并且當它不是陣列時,您正在使用 ngFor 來迭代 player_review 。這就是您收到此錯誤的原因。
檢查接收到的資料的結構,可能你要迭代的陣列包含在this.webService.getReview的回傳值的一個屬性中
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/400347.html
標籤:有角的
