Is there a way to track changes in the value of a variable within an Angular service?
I've been searching for a solution, but haven't been able to find one yet.
In my layout's header component, I have a counter that displays the number of items in the cart. This count is linked to the variable simsInCartLength
.
Within my service, I manage adding and removing items from the cart. There's a variable called noSims
that stores the current length of the cart item array.
How can I receive notifications when the service variable noSims
changes?
Component Code:
simsInCartLength = this.cartService.noSims;
Service Code (the variable updates whenever items are added or removed):
this.noSims = this.simsInCart.length;
Appreciate any help!