The Startup
Published in

The Startup

Adding Badge Notifications with Ionic 5 and Angular

Thanks to Pexels for the Cover Image

Getting Started

Adding the code

ionic cordova plugin add cordova-plugin-badgenpm 
install @ionic-native/badge
npm install cordova-plugin-badgenpm 
install @ionic-native/badge
ionic cap sync
import { Badge } from '@ionic-native/badge/ngx';
public notifyUser() {
if(thisUser.notifications.value >== 0){
this.badge.set(this.notifications.value);
}
}
public updateBadge() {
if(SOMETHING_HAS_CHANGED) {
this.badge.increase(NUMBER_TO_ADD_TO_CURRENT);
}
}
public updateBadge(countToDecrement) {
this.badge.decrease(countToDecrement);
}
public updateBadge(currentBadgeCount) {
if(currentBadgeCount === 0) {
this.badge.clear();
}
}

Issues I’ve Faced and Their Solutions

ERROR Error: StaticInjectorError(AppModule)[Badge]: 
StaticInjectorError(Platform: core)[Badge]:
NullInjectorError: No provider for Badge!
import { Badge } from '@ionic-native/badge/ngx';

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Thomas George

💻 1st Phorm #Ionic Mobile Applications #Developer ☕️ Espresso Fanatic 🇺🇸 Chauvinist www.thethomasgeorge.com