I am trying to get a response from a subscription that I have. I can see that I get to the cart component fine but the subscription doesn't seem to be working and I don't see any errors either. Here is my code
Service
@Output() event = new EventEmitter();
Products component
addToCart(product): void {
this._productsService.event.emit(product);
}
goToCart(): void {
this.router.navigate(['cart']);
}
Cart component
ngOnInit(): void {
console.log("gets here");
this._productsService.event.subscribe(product => {
console.log(product);
let index = -1;
index = this.cartProducts.findIndex(
p => p.id === product.id
);
this.cartProducts.push(product);
this.sum();
});
}