Factory:
factory('cordovaReady', function () {
return function (fn) {
var queue = [];
var impl = function () {
queue.push(Array.prototype.slice.call(arguments));
};
document.addEventListener('deviceready', function () {
queue.forEach(function (args) {
fn.apply(this, args);
});
impl = fn;
}, false);
return function () {
return impl.apply(this, arguments);
};
};
})
In a separate factory, I utilized the cordovaReady factory like this:
return {
getCurrentPosition: cordovaReady(function (onSuccess, onError, options) {
//
}
}
The cordovaReady factory is designed to execute the provided callback when the deviceReady event occurs. The question now is how can I incorporate it into a controller?
I attempted with the following code snippet:
.controller( 'HomeCtrl', function HomeController($scope, cordovaReady) {
cordovaReady(function(){
//do stuff
});
});
Despite no console errors being reported, this approach did not yield the desired outcome. Any suggestions on how to get this working?