carousels: any = []
的数组,但是每当我使用* ngFor循环遍历它时,我总是收到一条错误消息,指出“仅允许数组和可迭代对象”。该阵列内部的数据是从mLab获取的。 我的代码的目标是使用似乎有效的id从mLab更新对象。但是,每当我按下更新时,考虑到该更新甚至可以正常工作,为什么仍然出现错误?
我曾尝试将carousels: any = []
更改为carousels = []
,但似乎没有任何更改。
这是我的代码。
api.js(后端)
-这是与数据库通信的代码。router.route('carousel/update/:_id).put(function(req, res) {
db.collection('home').updateOne({"_id": ObjectId(req.params._id)}, {$set: req.body}, (err, results) => {
if (err) throw err;
res.send(results)
console.log(req.params._id)
});
});
home.service.ts
return this.http.put<any[]>('./api/carousel/update/' + id, {'header': newheader, 'subheader': newsubheader})
}
] >>声明:component.ts
carousels: any = [];
更新功能:
updateSlide(id: number){ this.HomeService.updateSlide(id, this.header, this.subheader).subscribe(slides => {this.carousels = slides}) }
更新有效,但仍然出现错误:尝试与'[object object]'进行比较时出错。仅允许数组和可迭代的对象
我在TS文件中有一个声明为轮播的数组:any = [],但是每当我使用* ngFor循环遍历它时,我都会不断收到错误消息,指出“仅允许数组和可迭代对象”。此数组中的数据...
。updateOne({})
不会返回对象列表,而是会返回具有有关行信息的对象。