These are chat archives for angular/material

7th
May 2018
Nico Mee
@nicoandmee
May 07 2018 10:29
Speaking of firebase & angular I'm banging my head against the wall trying to do something pretty simple in firestore, https://github.com/codediodeio/angular-firestarter using this as a base. I have a /users collection and each doc has a balance attribute. When a new item is added/button pressed I want the balance to decrease by one. Im new to angular though and I've managed to confuse myself, where exactly do I want to put my updateBalance method?
https://gyazo.com/092c1fd726afecbea6d12eb2435d3251 Here's what my firestore structure looks like, really simple stuff..
Adam
@avb100
May 07 2018 20:22

@nicoandmee You are going to want to update the field on the appropriate document. Something like:

userRef.update({balance: currentBalance - 1});

You will need to instantiate currentBalance, but that's the basic concept. The button handler function will need to be in your component class, but the component could, in turn, call a service that is injected into the component. See: Documents in AngularFirestore