2

I'm trying to use angularjs into my phonegap app. I have succesfully created the cordova project. And it's working. The "connecting" became 'devicer ready'. All is ok

I followed this way: use angularjs services to detected cordova 'ready' event.

See the code, the problem is at the end of the question

index.html

<!DOCTYPE html> <html ng-app="MyApp"> <head> <meta charset="utf-8" /> <meta name="format-detection" content="telephone=no" /> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> <link rel="stylesheet" type="text/css" href="css/index.css" /> <meta name="msapplication-tap-highlight" content="no" /> <title>Hello World</title> </head> <body ng-controller="MyController"> <div class="app"> <h1>Apache Cordova</h1> <div id="deviceready" class="blink"> <p class="event listening" ng-hide="ready">Connecting to Device</p> <p class="event received" ng-show="ready">Device is Ready</p> </div> </div> <script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="js/q.js"></script> <script type="text/javascript" src="js/angular.min.js"></script> <script type="text/javascript" src="js/fsCordova.js"></script> <script type="text/javascript" src="js/app.js"></script> </body> </html> 

Please notice I removed display: none; from css of .event.received into css file

fsCordova.js

angular.module('fsCordova', []).service('CordovaService', ['$document', '$q', function($document, $q) { var d = $q.defer(), resolved = false; var self = this; this.ready = d.promise; document.addEventListener('deviceready', function() { resolved = true; d.resolve(window.cordova); }); // Check to make sure we didn't miss the // event (just in case) setTimeout(function() { if (!resolved) { if (window.cordova) d.resolve(window.cordova); } }, 3000); }]); 

app.js

(function(){ var app = angular.module('myApp', ['fsCordova']); app.controller('MyController', function($scope, CordovaService) { this.ready = false; CordovaService.ready.then(function() { this.ready = true; }); }); })(); 

The problem ? Using the monitor tool of android SDK, I see in the log this error, from angular.ks

Error: $injector:modulerr Module Error Failed to instantiate module MyApp due to: Error: [$injector:nomod] http://errors.angularjs.org/1.2.20/$injector/nomod?p0=MyApp at Error () at file:///android_asset/www/js/angular.min.js:6:450 at file:///android_asset/www/js/angular.min.js:20:466 at file:///android_asset/www/js/angular.min.js:21:469 at file:///android_asset/www/js/angular.min.js:33:267 at Array.forEach (native) at q (file:///android_asset/www/js/angular.min.js:7:280) at e (file:///android_asset/www/js/angular.min.js:33:207) at dc (file:///android_asset/www/js/angular.min.js:36:309) at c (file:///android_asset/www/js/angular.min.js:18:139) 

I supposed I've a problem with a .js file missing of misspelled, but file names and file path are right.

Help me, please, to debug.

7
  • the file fscordova.js needs to be included as well Commented Jul 17, 2014 at 9:10
  • I modified the question, to add fsCordova.js. I retried, but the problem is still here. Commented Jul 17, 2014 at 9:12
  • What is q.js? have you tried to include angular.min.js file in the head section? Commented Jul 17, 2014 at 9:13
  • q is a mini js tool for work with promises (deferred, ...). I use it in fsCordova.js Commented Jul 17, 2014 at 9:14
  • 1
    aaaaggghhh! the ng-app needs to be myApp instead of MyApp Commented Jul 17, 2014 at 9:16

1 Answer 1

1

Change this code in your html markup:

ng-app="MyApp" 

to

ng-app="myApp" 
Sign up to request clarification or add additional context in comments.

2 Comments

I'm a stupid man ... sorry for waste of time .. Actually app starts, I cannot see the change from connecting to device ready, so I'll open a new question in a hour if I cannot find a solution by myself.
no worries man....you did the hard part to integrate phonegap! it happens!!do accept the answer if done!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.