diff --git a/js/angular/service/platform.js b/js/angular/service/platform.js index 71a7ac03af..3f16b1db29 100644 --- a/js/angular/service/platform.js +++ b/js/angular/service/platform.js @@ -177,6 +177,28 @@ IonicModule return ionic.Platform.is(type); }, + /** + * @ngdoc method + * @name $ionicPlatform#on + * @description + * Add Cordova event listeners, such as `pause`, `resume`, `volumedownbutton`, `batterylow`, + * `offline`, etc. More information about available event types can be found in + * [Cordova's event documentation](https://cordova.apache.org/docs/en/edge/cordova_events_events.md.html#Events). + * @param {string} type Cordova [event type](https://cordova.apache.org/docs/en/edge/cordova_events_events.md.html#Events). + * @param {function} callback Called when the Cordova event is fired. + * @returns {function} Returns a deregistration function to remove the event listener. + */ + on: function(type, cb) { + ionic.Platform.ready(function(){ + document.addEventListener(type, cb, false); + }); + return function() { + ionic.Platform.ready(function(){ + document.removeEventListener(type, cb); + }); + }; + }, + /** * @ngdoc method * @name $ionicPlatform#ready