Software Archive
Read-only legacy content
17061 Discussions

cordova - ionic - deviceraady event

Giovanni_S_
Beginner
238 Views

Hi,

in a project using Intel xdk, Cordova, Ionic, it seems there is a problem with the deviceready event: it seems that code was executed before the device was ready. I think the problem is how I write my custom code: in a separated custom js file (where I stored all the js code using ionic) linked from the index.html file of the project.

My custom js file (where I put all my custom code, linked from index.html) starts with somethings like this:

var myApp = angular.module('myApp', ['ionic','ngCordova']);

(myApp matchs with the ng-app directive in index.html)

After, I configured $StateProvider, controller etc...

Is this the right way of using Intel XDK?

If yes, how Intel XDK environment can run my code after the cordova deviceready event?

Thanks in advance!

 

 

 

 

 

0 Kudos
1 Reply
Pamela_H_Intel
Moderator
238 Views

Giovanni,

There are 2 ready events that are important and either one can finish first. The device needs to be ready and the DOM needs to be loaded.

Take a look at the following example where the app.Ready event ensures that both the DOM and device are ready and then triggers initEvent (where you can call your code):

Samples and Demos -> General -> HTML5 + Cordova (tab) -> Blank Cordova Starter App, particularly how the initEvents function is invoked after the app.Ready event occurs (look at www/js/app.js, www/js/init-app.js, and www/xdk/init-dev.js)

This sample is well-commented and hopefully will help you.

Pamela

0 Kudos
Reply