Angular 角度如何推到可观测阵列?英雄:可观察<;英雄[]>;
给定一个数组:Angular 角度如何推到可观测阵列?英雄:可观察<;英雄[]>;,angular,typescript,firebase,rxjs,angularfire,Angular,Typescript,Firebase,Rxjs,Angularfire,给定一个数组: // hero.service.ts hero: Observable<Hero[]>; //hero.service.ts 英雄:看得见; 您将如何执行类似的操作:hero.push(newHero)?不确定您想要实现什么,但因为您标记了firestore。我想您可以使用angularfirestorecollection,稍后将它们映射到可观测阵列 cardsCollection: AngularFirestoreCollection<Card>;
// hero.service.ts
hero: Observable<Hero[]>;
//hero.service.ts
英雄:看得见;
您将如何执行类似的操作:hero.push(newHero)?不确定您想要实现什么,但因为您标记了firestore。我想您可以使用angularfirestorecollection,稍后将它们映射到可观测阵列
cardsCollection: AngularFirestoreCollection<Card>;
cardDoc: AngularFirestoreDocument<Card>;
cards: Observable<Card[]>;
然后,您可以将卡添加到AngularFirestoreCollection
addCard(card: Card) {
this.cardsCollection.add(card);
}
希望这有帮助。如果您想查看我的完整代码和项目,请转到我的。Great的可能副本!你的例子帮助我理解了一些事情,让它对我有用!谢谢!:)我很高兴!您应该编辑适合您的解决方案的问题。
addCard(card: Card) {
this.cardsCollection.add(card);
}