我试图运行这段代码,但得到了一个错误。
this.resto.getList().subscribe((result)=>{
console.warn(result)
this.collection=result;
})我得到了一个错误:
core.js:7990 ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
Type '{}' is not assignable to type 'any[] & Iterable<any>'.
Type '{}' is not assignable to type 'any[]'.发布于 2021-02-04 01:40:25
这解决了我的问题
collection = <any>{};您可以循环遍历TypeScript中的对象,也可以使用以下命令:
collection = <any>[];发布于 2021-05-12 06:02:55
collection = <any>{};为我工作得很好,因为我也面临着同样的问题。这可能是由于对象在函数中的预期内容和返回内容之间不匹配造成的。
我还建议在您的tsconfig.json文件中包含"strictPropertyInitialization": false。
https://stackoverflow.com/questions/65040940
复制相似问题