【发布时间】:2021-05-02 19:10:16
【问题描述】:
我目前正在尝试将 Observable 转换为数组,以便我可以使用 ngFor 遍历 HTML 中的数组。
这是我目前的 Typescript 代码。当我控制台记录 testArray 数组时,它说它是未定义的。
item$: Observable<any[]>;
testArray: Array<any[]>;
constructor(
private afs: AngularFirestore,
private route: ActivatedRoute,
) {
this.item$ = afs.collection('testsTaken', ref => ref.where('testCreator', '==', this.id).where('testTitle', '==', this.testTitle)).valueChanges();
this.item$.subscribe(x => this.testArray = x);
console.log(this.testArray); // yields undefined
}
I tried the advice given for this post and I still cant get it to work
【问题讨论】:
标签: javascript arrays angular rxjs observable