javascript - Manually bootstrapping AngularJS from Cordova deviceready event -


I am using Cordova 3.3.1-0.4.2 and Kanji 1.2.13

I need once I organize the 'Cordova' device startup, to manually configure the bootstrap.

I'm testing with Cordoba Run Android on Nexus 5, but I'm behaving like this on an iPhone.

In order to make the problem easier, this JS is going on in the global document area. & lt; / Body & gt; The scripts are being loaded before the tag.


This works:

  angular.bootstrap (document. GetElementById ("app"), ["MyApp"]);  

This does not work:

  function init () {angular.bootstrap (document.getElementById ("app"), ["MyApp"] ); } Document.addEventListener ('deviceready', function) (init ();}, true);  

However, if I add the alert ("init") to the init method that shows that I am running as well (angular) and alerts ( Document.getElementById ("app")) show that they exist.

I do not understand why, why has been given, init () is being called, it does not work

Anyone?

Any

"post-text" itemprop = "text">

I have found that the best solution is normally bootstrap in the form of a corner and Then load the Cordova as a module, which promises, which is resolved when the device is ready. {$ Cordova service ', [' $ document ',' $ timeout ',' $ window ',' $ q ', function ($) document, $ timeout, $ window, $ Q) {var defer = $ q .defer (); This.ready = defer.promise; // Backup in this case that we did not receive the event // It seemed that with some versions of Cordova // when a web browser is tested in the 'Cordova service' / but when the device is correct on the device Received in the form var timoutPromise = $ timeout (function () {if ($ window.cordova) {defer.resolve ($ window.cordova);} and {defer.reject ("failed to load cordova");} }, 1200); Angular.element ([document] [0] .addEventListener ('deviceready', function () {$ timeout.cancel (timoutPromise); defer.resolve ($ window.cordova);}); }];

Usage:

  Angular Module ('app', ['FSO cordova']). Run (['$ window', function ($ window) {// incl. Fastclick fastclick.actack (connier.ment ($ window.document.body) [0]);}]). Controller ('AppCtrl', ['$ scope', 'Cordova service', function ($ amount, Cordova service) {$ scope.ready = false; // Cordoba is ready when cordova service .ready.then (function solve (resp ) {$ Scope.ready = true;}, function rejected (resp) {new error (resp);});}]);  

I have shared this Bootstrap project


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -