My cart-component code is
<ng-template #mymodal let-modal>
<div class="modal-wrap">
<div class="modal-header">
<h5 class="modal-title" id="modal-basic-title">Removing Item from Cart...</h5>
</div>
<div class="modal-body">
Are you sure? Proceeding will remove item from cart.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="removeItem(item)">Yes</button>
<button type="button" class="btn btn-danger" (click)="modal.close('Save click')">No</button>
</div>
</div>
</ng-template>
Modal Code in component.ts
open(content: any) {
this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}
private getDismissReason(reason: any): string {
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
Cart Code in component - this uses the cart service
removeItem(item: any){
this.cartService.removeCartItem(item);
}
Cart Service Code
removeCartItem(product: any){
this.cartItemList.map((a:any, index:any)=>{
if(product.id=== a.id){
this.cartItemList.splice(index,1);
}
})
this.productList.next(this.cartItemList);
}
How do I make this work? Intial error - Propery 'item' does not exist on type 'AddtoCartbutton', I tried declaring item in cart component but when I press delete button I get undefined.