feat(cordovaEvents): $ionicPlatform.on method

Create $ionicPlatform.on(type, callback) to make it easier to add
Cordova event listeners. Closes #2219
This commit is contained in:
Adam Bradley
2014-09-16 08:55:00 -05:00
parent 37d75f7f5d
commit 046ad53b20

View File

@@ -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