2017-04-10 70 views
0

我的GET路線有問題。正如標題所述。 HTML代碼:「無法找到類型爲'object'的不同支持對象'[object Object]',NgFor僅支持綁定到Iterables,如數組。

<ion-card *ngFor="let room of rooms"> 

組件:

rooms : any; 
this.rooms = this.roomsService.getRooms(); 

提供者:

getRooms(){ 
return new Promise(resolve => { 
    this.http.get('http://localhost:8080/api/rooms/') 
    .map(res => res.json()) 
    .subscribe(data => { 
     resolve(data); 
    }); 
}); 

}

和服務器端:

exports.getRooms = function (req, res) { 
Room.find({}, function (err, rooms) { 
    if (err) { 
     res.send(err); 
    } else { 
     res.json(rooms); 
    } 
}); 

}

我在做什麼錯?返回JSON的

結構:

[ { _id: 58eb65dcfd9b3c188c74d811, 
room_number: 1, 
type: 'standard', 
beds: 1, 
max_occupancy: 1, 
cost_per_night: 50, 
__v: 0, 
reserved: [] }, 
{ _id: 58eb6608fd9b3c188c74d812, 
room_number: 2, 
type: 'standard', 
beds: 1, 
max_occupancy: 1, 
cost_per_night: 55, 
__v: 0, 
reserved: [] } ] 
+1

什麼是返回的數據結構? – Groben

+0

分享json結構 – Srigar

+0

添加到第一篇文章 –

回答

0

我曾經在一個相當簡單的方式解決了這個。有什麼問題:

this.rooms = this.roomsService.getRooms(); 

因爲我不能直接給這樣的承諾,所以我所做的:

this.roomsService.getRooms().then((data) => { 
    this.rooms = data; 
}, (err) => { 
    console.log(err); 
}); 
相關問題