I'm new in angular and firebase so it is not clear for me. I am now working on an e-commerce application specifically on the shopping cart page. I have a collection in the database called 'cart' which contains products as documents and i get its data stored in an array of objects in my cart.component.ts file. Then I loop this array in the cart.component.html file to display its data as the cart items. All of this works perfectly, but what I'm trying to do now is to link the value of 'qty' with its value in the database, So when the user changes it, it is changed in the database as well.
here is (cart.component.ts) file:
import { Component, OnInit } from '@angular/core';
import { Goods } from 'src/app/interfaces/goods';
import { CartService } from './../../services/cart.service';
@Component({
selector: 'app-shopping-cart',
templateUrl: './shopping-cart.component.html',
styleUrls: ['./shopping-cart.component.scss']
})
export class ShoppingCartComponent implements OnInit {
cartGoods: Array<Goods>;
constructor(private cartSer: CartService) {}
ngOnInit() {
this.cartSer.getCartGoods().subscribe(data => {
this.cartGoods = data.map(el => {
return {
id: el.payload.doc.id,
...el.payload.doc.data()
};
});
});
}
}
here is (cart.component.html) file:
<ul class="cart">
<li *ngFor="let good of cartGoods">
<img [src]="good.img" [alt]="good.name">
<h4 class="name"> {{ good.name | titlecase }} </h4>
<strong class="price"> {{ good.price | currency }} </strong>
<input class="qty" type="number" [(ngModel)]="good.qty">
</li>
</ul>