Paco Zevallos
Paco Zevallos

Reputation: 2295

update value document ID firestore

I need to update a document value from a collection in Firestore. I have the following that works for me but only for an ID document. But if I have a thousand records how do I update them? How do I get the document ID automatically?

https://stackblitz.com/edit/angular-ea3wme

What I need is that every time I click on the update button the value of thestate column (of that row) changes to false.

enter image description here

myService.ts

updateEstado(){
  this.afs.doc('domiciliarios/OI4GXrNTLncFQpaXajdy').update({
    estado : false
  });
}

myComponent.ts

actualizarEstado(){
  this.fs.updateEstado();
}

myComponent.html

<td>
    <button class="btn btn-outline-primary btn-sm" (click)="actualizarEstado()">Editar</button>
</td>

Upvotes: 0

Views: 1814

Answers (1)

Ankur
Ankur

Reputation: 191

Your button should send the key when calling the function just like this:-

myComponent.html

<td>
   <button class="btn btn-outline-primary btn-sm" (click)="actualizarEstado(domiciliario.id)">Update</button>
</td>

myComponent.ts

actualizarEstado(key){
    this.fs.updateEstado(key);
}

myService.ts

updateEstado(key){
    this.afs.doc('domiciliarios/' + key).update({
      estado : false
    })
}

Hope this will help.

Upvotes: 2

Related Questions