Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
angularfire2 gets new pushid before saving model object

With angulafire it was possible to retrieve a record pushid before saving it to the database:

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

This was handy, as I could store the firebase key as property of my model.
Now with angularfire2 this does not seem possible in a clean/simple 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 whether I am approaching firebase in a wrong way (wishing to have a key property bound to my model for convenience) or if there is a better way to add the pushid to newly added records.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Take a look at this answer on angularfire2's issues

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);
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!