Issue
I want to make this.id equal to doc.id or the cont id from the previous function instead of the hardwired value I have in there.
I'm not sure on the correct syntax to get this done.
addToCart(){
this.db.firestore.collection('products')
.where('tagid','==', "049a1092285e80")
.get()
.then(querySnapshot => {
querySnapshot.forEach(function (doc) {
const id = doc.id;
//const data = doc.data;
console.log("debug 1 ",doc.id); // id of doc
console.log("debug 2 ", doc.data()); // data of doc
console.log("debug 3", id);
//return {id};
}) // end of for each
// want to make this.id = doc.id
this.id = "KCSx3JPeoerFmeH5zW7R";
this.productService.getOneProduct(this.id).subscribe(res => {
this.product = res;
this.product.id = this.id;
this.amount = this.cartService.getItemCount(this.id);
console.log('tag id', this.product.tagid);
this.cartService.addProduct(this.product);
});
});
}
Solution
Good day!
Just use the arrow function to save context and modify id
property:
querySnapshot.forEach(doc => { this.id = doc.id; })
Answered By - AlexanderFSP
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.