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: [] } ]
什麼是返回的數據結構? – Groben
分享json結構 – Srigar
添加到第一篇文章 –