Using Ionic v1, I am trying to call a function in my controller when an event listener in my app.run fires. The event is created by a Cordova (Phonegap) plugin that detects changes in the headphone jack.
I must be doing something wrong because I can't find a solution that works. Here is my example:
(function() {
var app = angular.module('mymodule', ['ionic']);
app.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.HeadsetDetection){
/*Monitor for changes in the headphone jack*/
document.addEventListener('deviceready', function() {
window.HeadsetDetection.registerRemoteEvents(function(status){
// *HERE* is where I want to call or somehow trigger
an action in my controller
});
}, false);
}
});
});
When the headphone jack is sensed I am trying to close an ionic popup created in my controller.