Reputation: 506
I know how to READ and WRITE a document in Firestore, But how does one update() a Value of and object in an array of Maps without removing/deleteing? Just changing one value if needed.
I have a Form that includes a FormArray, that are able to edit as an when there is an update on the price list.
product = {
id: "product id",
brand: "Brand Name",
model: "This is the model of the brand"
lists: [
{ location: "Location 1", price: "0.00" },
{ location: "Location 2", price: "0.00" }
]
}
Component.ts
export class PageComponent implements OnInit {
productDoc: AngularFirestoreDocument<Product>;
product: Observable<any>;
}
constructor(private afs: AngularFirestore) {}
update() {
this.productDoc.update({ amount: this.updatedProduct });
}
Appreciate to shine some light on it, Thank You!
Upvotes: 4
Views: 2526
Reputation: 598708
There is no way to change a value in an array. You'll either have to remove the old combination of values and add the new combination, or have to:
Alternatively, you can store the lists in a map field rather than an array field, meaning that you give a name to each set of values - and you can the use dot notation to update the nested field.
Upvotes: 8