I am currently using Cordova version 3.3.1-0.4.2 along with Angular 1.2.13
My goal is to manually bootstrap Angular once the 'deviceready' event in Cordova is triggered.
During my testing on a Nexus 5 with the command cordova run android
, I encountered the same issue while testing on an iPhone.
To simplify the scenario, the JavaScript is running in the overall document scope. The scripts are loaded before the closing </body>
tag.
This method works as intended:
angular.bootstrap(document.getElementById("app"), ["MyApp"]);
However, this approach does not work:
function init(){
angular.bootstrap(document.getElementById("app"), ["MyApp"]);
}
document.addEventListener('deviceready', function () {
init();
}, true);
Strange enough, if I add alert("init")
to the init function, it shows that the function IS being executed. Furthermore, alerts for (angular) and (document.getElementById("app")) confirm their existence.
I find it puzzling why, even though the init() function is being called, it fails when invoked from the EventListener callback but works perfectly when called directly.
Any insights or suggestions on this matter?