Background: I'ev succesfully integrated angular.js within phonegap 'base' application, the one created from cordova framework itself.
To detected cordova onReady event I created this
angular.module('fsCordova', []).service('CordovaService', ['$document', '$q',
function($document, $q) {
console.log ("fsCordova initialized");
var d = $q.defer(),
resolved = false;
var self = this;
this.ready = d.promise;
document.addEventListener('deviceready', function() {
console.log ("deviceready received");
resolved = true;
d.resolve(window.cordova);
});
// Check to make sure we didn't miss the
// event (just in case)
setTimeout(function() {
if (!resolved) {
console.log ("fsCordova timout, deferred resolved manually");
if (window.cordova) d.resolve(window.cordova);
}
}, 3000);
}]);
This my app main js
(function(){
var app = angular.module('myApp', ['fsCordova']);
app.controller('MyController', function($scope, CordovaService) {
$scope.ready = false;
CordovaService.ready.then(function() {
console.log ("CordovaService.ready received");
$scope.ready = true;
});
});
})();
What I'm trying to do: thanks to this service, I want to resolve manually the deferred when loading index.html from Google Chrom Browser on Windows 7, thanks to timeout waiting for an event that, on a pc, will never occours.
What is working: I can see fsCordova initialized
, I see deviceready received
. On a Android emulator and on Android phisical device, I see in adb console even the CordovaService ready received
message. So on android all is working
Problem: on a desktop pc, I can see fsCordova initialized
, I see deviceready received
and I see deferred resolved manually
. But I can't see the CordovaService ready received message
; $scope.ready = true;
was not executed, so, really, I can't test it on my pc.
So, I think that my way to manually resolve the promise on timeout has something wrong.
Please, so, note that problem is NOT cordova. Something goes wrong with q or with angularJs