Reputation: 213
I have created one application for shopping cart. Everything is working good, but i have removed document.location.href
for redirection instead of i have used this.router.navigate['/products']
.So cart details is not reset properly. I tried to resolve the issue but not working. If anyone can help to find the solutions?
Upvotes: 1
Views: 758
Reputation: 9301
Made changes in src/app/services/cart.service.ts
emptyCart(){
this.cartData =[];
this.listCartItems();
}
https://stackblitz.com/edit/angular-selvam-ecommerce-task-cnstaj
Reason document.location.href works because after reseting dictionary redirecting to new page.
When you navigate router of Angular its doesnt redirect, its just changes routes. In this reset is not happening.
For clearing cart when click on "Place New Order"
inside function clearCart()
in checkout.dir.ts
this.cart.emptyCart();
before this line :
this.router.navigate(['/products']);
Upvotes: 1