Find Device Network enable and disable status in ionic - cordova app

In Ionic application the event “offline” and “online” can be added using addEventListener(). These events are attached to the document. The following are the sample codes, the respective callbacks will get fired once the device data connection enabled or disabled.

Example 1 - Online

document.addEventListener("online", onNetworkOnline, false);
function onNetworkOnline() {
  alert('Internet Connected);

Example 2 - Offline

document.addEventListener("offline", onNetworkOffline, false);
function onNetworkOffline() {
  alert('Internet Disconnected);