Given your example of your tabs, this should work:
<ion-tab [root]="tab1Root" tabIcon="home" tabBadge="{{tab1BadgeCount}}" tabBadgeStyle="danger"></ion-tab>
With a simple controller:
export class TabsPage {
tab1Root: any = SomePage;
tab1BadgeCount : number = 0;
constructor() {
}
incrementBadgeCount(){
this.tab1BadgeCount = this.tab1BadgeCount+1;
}
decrementBadgeCount(){
this.tab1BadgeCount = this.tab1BadgeCount-1;
}
}
You can connect these methods to one button for testing.
However, I would recommend using Events to control the change in the number of icons, for example.
export class TabsPage {
tab1Root: any = SomePage;
tab1BadgeCount : number = 0;
constructor(public events: Events) {
}
incrementBadgeCount(){
this.tab1BadgeCount = this.tab1BadgeCount+1;
this.publishBadgeCountUpdate();
}
decrementBadgeCount(){
this.tab1BadgeCount = this.tab1BadgeCount-1;
this.publishBadgeCountUpdate();
}
}
subscribeToBadgeCountChange(){
return this
.events
.subscribe("tabs-page:badge-update", this.refreshBadgeCount());
}
publishBadgeCountUpdate(){
return this
.events
.publish("tabs-page:badge-update");
}
refreshBadgeCount(){
}
ionViewWillEnter() {
this.subscribeToBadgeCountChange();
}
}
source
share