Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda