Software Archive
Read-only legacy content
17061 Discussions

Need help to include ngCordova

Mark_Z_1
Beginner
1,209 Views

I need help on the proper step to include ngCordova into my project. I'm using XDK with Ionic blank project as seed.

I tested Ionic and AngulaJS working without problem.

But when I try to include ngCordova, my AngularJS stop working. Please see the screenshot for easier understanding.

Please point me some light, what I did wrong? Please advice.

116237454ffe4043909846cc1e6ce1a1c0af6030a9328.png

11624379d35483c004b2df0b8b97d10e71cdc6ddc59d3.png

116252c387a5bbc1ce4f394becda025158e1251c0d732.png

Please help! What I did wrong here?

0 Kudos
9 Replies
SithLord
New Contributor I
1,209 Views
Thanks for bringing the existence of ngCordova to my attention. In your last screenshot hit the icon in the top left corner that looks like a bug. Check the console of javascript errors as it may give you some indication as to what is breaking the scripts. (function () { //You may be calling angular code too quickly, try moving the app.js include to just before the close of the body tag. Plus i dont see you including the full angular.min.js lib. Does ngCordova bundle it? })(); " "
0 Kudos
Mark_Z_1
Beginner
1,209 Views

Hello SithLord,

I tested move the app.js line to before body tag closing. Same error as seen below. I'm new to explore Angular and Ionic, so I didn't understand much what is this error mean. Do you have any idea? I can provide more info if you need. Thanks.

ngCordova-XDK-error.png

0 Kudos
SithLord
New Contributor I
1,209 Views

you need to include ngRoute, angular.module('IonicApp', ['ionic', 'ngCordova', 'ngRoute'] and on your index.html

 

<script type="application/javascript" src="https://code.angularjs.org/1.3.15/angular-route.min.js"></script>

 

0 Kudos
Mark_Z_1
Beginner
1,209 Views

Hi, I tried do what you advice but it's the same result.

0 Kudos
SithLord
New Contributor I
1,209 Views

Mark Z. wrote:

Hi, I tried do what you advice but it's the same result.

Make sure you are using the current version of the core AngularJS library as well

<script type="application/javascript" src="https://code.angularjs.org/1.3.15/angular.min.js"></script>
<script type="application/javascript" src="https://code.angularjs.org/1.3.15/angular-route.min.js"></script>

 

I added ng-cordova.min.js to my existing app and it broke my app with the same error. Including ngRoute resolved the problem for me so i dont know what else to  try.

btw, my test was using ngCordova in a AFUI project not Ionic so its possible your issue is specific to ionic being in the mix and not just angular related.

 

0 Kudos
Mark_Z_1
Beginner
1,209 Views

Hope someone else have idea on what is happening here. I tried your second advice, failed with same error.

0 Kudos
Adam_G_
New Contributor I
1,209 Views

Are you able to share the code/project for people to look at?

0 Kudos
Barry_Johnson
New Contributor I
1,209 Views

At a minimum, no pun intended, I would recommend loading the non-minimized version of ng-cordova.js so you can actually see and report what the error is.

Also, shouldn't the library code load ahead of your app code?

0 Kudos
Mark_Z_1
Beginner
1,209 Views

Hello everyone,

I fixed the problem by adding:

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

ui.router instead of ngRoute. Fixed. Not sure which part cause the conflict yet.

0 Kudos
Reply