Angularfire2 gets a new pushid before saving the model object

Using angulafire it was possible to extract the pushid file before saving it to the database:

 myModelDto.key = dbRef.push().key; // Add the myModelDto to the relative colletion 

This was convenient since I could store the firebase key as a property of my model.
Now with angularfire2 this is not possible in a simple / easy way:

 constructor(private angFire: AngularFire) { this.placeRef$ = angFire.database.list('/places'); } insertPlace = (place: IPlace): firebase.Thenable<IPlace> => { return this.placeRef$.push(place) .then(item => { place.id = item.key; this.placeRef$.update(item.key, place) }); 

Therefore, I am wondering if I am approaching firebase in the wrong way (wanting for convenience a key property bound to my model to be bound) or if there is a better way to add pushid to newly added records.

+5
source share
1 answer

Take a look at this answer to angular fire problems.

https://github.com/angular/angularfire2/issues/199

kanafghan writes:

 const pushId = this.afDb.createPushId(); const item = { ...item, id: pushId }; this.afDb.list('items').set(item.id, item); 
0
source

Source: https://habr.com/ru/post/1267027/


All Articles