我在从数据库中检索数据时遇到错误。
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
我尝试了所有剩余的响应,但没有得到确切的解决方案。
我的service.ts:
users: User[];
getAllUsers(){
return this.http.get(environment.apiBaseUrl + '/users');
}
我的component.ts:
refreshUserList(){
this.userService.getAllUsers().subscribe((res) => {
this.userService.users = res as User[];
})
};
我的component.html:
<tr *ngFor="let use of userService.users">
<td>{{ use.fullName }}</td>
</tr>
最佳答案
因此,使用下面的内容,您可以看到响应不是数组,但其中一个字段是数组。因此,您必须迭代数组字段。
*ngFor="let use of userService.users?.docs"
关于javascript - Angular 7 找不到类型为 '[object Object]' 的不同支持对象 'object'。 NgFor 仅支持绑定(bind)到 Iterables,例如 Arrays,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54767171/