Hi,
I’m realizing an app that have a wishlist.
I’m saving all data that i need in storage and use a service with method to get and set value.
My app is a tab-bar app of Ionic 6 + Angular 14.
I need to show a badge on bottom tab with a dynamically number that count how much item are in the wishlist.
It have to increase when i save 1 new item and decrease when i remove 1 from wishlist.
I read this topic: Update tabs badge total from a different component - #10 by skinny_jones but i wasn’t able to show the content of variable (on run app show [object Object])
This is how i call the variable in my template:
<ion-badge>{{savedNumber$}}</ion-badge>
and this is my ts file variable:
savedNumber$: Observable<number>;
constructor(
private load: LoadDataService,
) {}
//some code
this.savedNumber$ = this.load.listSize;
and this is my service.ts:
export class LoadDataService {
savedProductId = [];
//some code
private listSizeSubject: Subject<number>;
private _listSize: Observable<number>;
constructor(
//some code
){
this.listSizeSubject = new Subject();
this._listSize = this.listSizeSubject.asObservable();
}
get listSize(){
return this._listSize;
}
//some code
addToWishlist(/*some item*/){
//some code
this.savedProductId.push(this.uniqueInfo['id']);
this.storage.setItem('savedProductId', this.savedProductId);
this.listSizeSubject.next(this.savedProductId.length);
}
Searching on internet i founded a topic that talking about NGRX and *ngrxLet to show the value but i didn’t understand how it work or how use it. (this is the link for more info: https://ngrx.io/guide/component/let)
I really appreciate some help, i can’t get out of it.
Thanks in advance