Cordova + Angularjs + Device Ready

Anwer picture Anwer · Feb 4, 2014 · Viewed 47.5k times · Source

I am developing a mobile application using Cordova and AngularJS. How do I restrict bootstrapping of AngluarJS before Cordova device ready. Basically I don't want to use any of AngularJS controllers before device ready.

Answer

TheHippo picture TheHippo · Feb 4, 2014

Manually bootstrap your Angular app:

Remove your ng-app attribute from your HTML code, so Angular doesn't start itself.

Add something like this to you JavaScript code:

document.addEventListener("deviceready", function() {
    // retrieve the DOM element that had the ng-app attribute
    var domElement = document.getElementById(...) / document.querySelector(...);
    angular.bootstrap(domElement, ["angularAppName"]);
}, false);

Angular documentation for bootstrapping apps.