Skip to content

Instantly share code, notes, and snippets.

@Ademking
Last active July 20, 2018 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ademking/bdc6458665a938fc59fdbfa2cef3e484 to your computer and use it in GitHub Desktop.
Save Ademking/bdc6458665a938fc59fdbfa2cef3e484 to your computer and use it in GitHub Desktop.
πŸ’™ Ionic 3 : Test network connectivity

App.Component.ts

export class MyApp {
  constructor (
    private network: Network,
    private platform: Platform,
    private alertCtrl: AlertController,
  ) {
    platform.ready().then(() => {
     // no internet --> do :
      this.listenConnection();
    })
  }

  private listenConnection(): void {
    this.network.onDisconnect()
      .subscribe(() => {
        this.showAlert();
      });
  }

  private showAlert(): void {
    // do the alert thing ...
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment