J. *_*nor 5 firebase firebase-realtime-database angularfire2 angular
我想使用ngFor
Angular 2将 Firebase 查询的结果绑定到我的模板。这很容易在下面实现。
成分:
export class FeaturedThreadsComponent {
threads: FirebaseListObservable<any[]>;
qualitySubject: Subject<any>;
constructor(af: AngularFire) {
this.qualitySubject = new Subject();
this.threads = af.database.list('/threads', {
query: {
orderByChild: 'quality',
endAt: 5
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
模板:
<div *ngFor="let thread of threads | async">
{{thread.title}}
</div>
Run Code Online (Sandbox Code Playgroud)
但是如果我想使用ngFor
嵌套在模板中的另一个指令来列出子对象的键......
<div *ngFor="let thread of threads | async">
{{thread.title}}
<div *ngFor="let participant of thread.participants">
{{participant.$key}}}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我收到控制台错误, Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
在我的数据库结构中,participants
是 的子项thread
,它是threads
wherethread
是动态键的子项。所以我不能使用直接路径到participants
.
这种嵌套ngFor
指令模式在简单地迭代本地文件的服务中工作得很好。为什么它在这里不起作用对我来说似乎有点模糊。
归档时间: |
|
查看次数: |
1777 次 |
最近记录: |