I am encountering an issue with my ShareService in angular 2. In another component, I have subscribed to it and the following is my code snippet:
*******ShareService ***********************************
private ShopItem$ = new Subject<any>();
ShopItem$_ = this.ShopItem$.asObservable();
public addToCart(item : any){
this.ShopItem$.next(item);
}
*************in another component**********************
_shareService.ShopItem$_.subscribe((item) => {
alert("hiii"); <====>this functions execute twice
this.ADD_TO_CART(item);<====>this functions execute twice
});
I am experiencing a problem where the ADD_TO_CART() function is executed twice! This is causing issues in my cart functionality. How can I resolve this issue? It seems that the ShareService itself is working fine as I have tested it with a different function and it only executes once.