Phonegap/Cordova Events Support


#1

Ionic uses the devicereadyto initialize the AngularJS app. Is there any way to bind to the other Phonegap/cordova events (http://docs.phonegap.com/en/edge/cordova_events_events.md.html#Events) inside our AJS app?


#2

I contain them all in a separate phonegap-events.js file and reference it after phonegap.js in my index.html.

I’m sure there is a more AngularJS approach but this works for my requirements.

phonegap-events.js contents:

document.addEventListener("resume", onResume, false);
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);

function onResume() {
}

function onOnline() {
  document.getElementById('connection-warning').style.display = 'none';
}

function onOffline() {
  document.getElementById('connection-warning').style.display = 'block';
}

#3

It actually works in an angular controller. I’ve tried Cordova’s resume and pause event. The others should work the same. deviceready might not work because I’ve seen Ionic removing the event listener, but haven’t verified that.

angular.controller('AppCtrl', function () {
  document.addEventListener("resume", onResume, false);
  document.addEventListener("pause", onPause, false);

  function onResume() {
    console.log('On Resume');
  }

  function onPause() {
    console.log('On Pause');
  }
});

#4

How can i get the $scope on resume method? It is possible?
I need refresh a list inside a controller after on resume!