Adding Event Listener to page (not the whole app)

Right now I add a couple of event listeners to check when the phone goes online/offline.

document.addEventListener('online', onOnline, false);
document.addEventListener('offline', onOffline, false);

This works fine, but since I’m attaching the listener to the document, it applies to every page in my app.

How would I do this for only one page? (Or several maybe, but not the whole app).

You could use the network information events from ionic-native

http://ionicframework.com/docs/v2/native/Network/

how to use this now. your link not working

1 Like