How can I throw an error message when there’s no network connection?
I checked documentation of Network plugin but I couldn’t get it to work properly…
I’m trying to use AlertController to display an error message.
and the network should be checked in IonDidViewLoad().
Any code example would be appreciated!
Btw. You could initialize your subscriptions in the network service constructor, but I’ve choosen to initialize them myself calling the “setSubscriptions()” function when “platform.ready()”.
After reading my post again, I noticed that one could call the “setSubscriptions()” function multiple times. I’ve added a “subscribedToNetworkStatus” boolean to the original answer. When set to true, this will prevent a user initiating multiple subscriptions when calling the function multiple times.
private subscribedToNetworkStatus: boolean = false;
...
// update in setSubscriptions()
if (!this.subscribedToNetworkStatus && this.platform.is("cordova")) {
this.subscribedToNetworkStatus = true;
}