mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
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:
22
js/angular/service/platform.js
vendored
22
js/angular/service/platform.js
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user