【发布时间】:2025-11-27 09:50:02
【问题描述】:
我已经创建了一个从 Firebase 获取数据的变量。它返回一个包含两个部分的对象到其中的对象,但是当我尝试使用字符串插值时,它返回[object Object]。我试过做一个 *ngFor 但是我得到这个错误:
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays
这是我的变量:
this.groupMembers = this.currentGroup.members_uid;
console.log(this.groupMembers)
console.log 在控制台中返回:
{7TkrG4Ty2pf2OBy9whhSsSl1sC22: true, by285gAhkdRg4rDMkujzSQXxGAJ2: true}
7TkrG4Ty2pf2OBy9whhSsSl1sC22
:
true
by285gAhkdRg4rDMkujzSQXxGAJ2
:
true
__proto__
:
Object
如何访问它以在我的 html 中显示其内容?
如何在我的 ts 文件中创建一个新变量,该变量也以某种方式“循环”它们,以便我可以单独访问每个部分?
编辑****
this.currentGroup = this.currentGroupId$
.pipe(switchMap(id => this._group.getGroupById(id).valueChanges()))
然后返回一个 Observable,我将其输入到子组件中,如下所示:
*ngIf="currentGroup | async as group" [currentGroup]="group"
并称之为:
@Input() currentGroup: any;
【问题讨论】:
-
你能展示从 Firebase 获取数据的代码吗?
-
@WazzaEl 更新了我的问题
标签: javascript html angular typescript firebase