Given an array:
// hero.service.ts
hero: Observable<Hero[]>;
How would you do something similar to: hero.push(newHero)?
Given an array:
// hero.service.ts
hero: Observable<Hero[]>;
How would you do something similar to: hero.push(newHero)?
Not sure what you are trying to achieve, but since you tagged firestore. I guess you could use angularfirestorecollection and map them to observable array later.
cardsCollection: AngularFirestoreCollection<Card>;
cardDoc: AngularFirestoreDocument<Card>;
cards: Observable<Card[]>;
On init you will bind them together.
ngOnInit() {
this.cards = this.cardsCollection.snapshotChanges().map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as Card;
data.id = a.payload.doc.id;
return data;
});
});
}
and then you can add cards to AngularFirestoreCollection.
addCard(card: Card) {
this.cardsCollection.add(card);
}
Hope this helps. If you want to see my full code and project go to my github.