Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda