我如何用我从Angular(Firebase)Firestore检索的数据运行ngFor循环?

问题描述 投票:0回答:1

这是我的代码。

export class ErrandsComponent implements OnInit {
  private itemsCollection: AngularFirestoreCollection<Item>;
  items: Observable<Item[]>;  
  constructor(private db: AngularFirestore) { 
    this.itemsCollection = db.collection<Item>('errands');
    this.items = this.itemsCollection.valueChanges();
  }


  ngOnInit(){
      var errands = Array.of(this.items);
      console.log(this.items)
  };



}

我想把Observable的集合(Observable,现在只有一个)变成一个Array的过程是因为我得到了一个错误,说明:

NgFor只支持绑定Iterables,如Arrays。

我的目标是使用我的集合中的数据,并在模板中做一个ngFor,以显示出 listlocation.

angular firebase google-cloud-firestore angularfire2 angularfire
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.