Ionic Check Internet Connection
Ionic Check Internet Connection – To check internet connection cordova-plugin-network-information is used, here in this tutorial, we are going to explain how you can use this plugin to check the internet connect in Ionic Framework. You can also use our online editor to edit and run the code online.
Supported in Ionic 2 & version > 2.
Ionic Check Internet Connection Example
First of you need to install the cordova and ionic native plugins-
Example:
$ ionic cordova plugin add cordova-plugin-network-information $ npm install --save @ionic-native/network |
- Amazon Fire OS
- iOS
- Android
- Windows
- Browser
Example
Here is simple example to detect internet connection in ionic framework.
import { Network } from '@ionic-native/network'; constructor(private network: Network) { } // watch network for a disconnect let disconnectSubscription = this.network.onDisconnect().subscribe(() => { console.log('Disconnected..'); }); disconnectSubscription.unsubscribe(); let connectSubscription = this.network.onConnect().subscribe(() => { console.log('Connected to internet sucessfully.'); }); connectSubscription.unsubscribe();
Advertisements