how i call api only if internet is availale in ionic 4. If internet is not available Api should not call
networkcheck(){
this.network.onDisconnect().subscribe(() => {
this.closeActiveAlertPopup();
this.router.navigate([’/networkcheck’]);
});
this.network.onConnect().subscribe(() => {
this.IdentityService.checkAuthenticatedUser(); //call here your service
});
}
i use this but this not working both alert are not working
networkcheck(){
this.network.onDisconnect().subscribe(() => {
alert('inside unsuscribe');
this.userAlert.showError('internet is not available');
// this.closeActiveAlertPopup();
// this.router.navigate([’/networkcheck’]);
});
this.network.onConnect().subscribe(() => {
// this.IdentityService.checkAuthenticatedUser(); //call here your service
alert('insert subscribe');
this.getData();
this.validatedata();
});
}
try this
if (this.network.type !==’ none’) {
call this…
}
1 Like
thanks