最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - cordova is not defined - cordova.js has already been loaded :: Ionic - Stack Overflow

programmeradmin5浏览0评论

During the app running, this is what I get:

Uncaught ReferenceError: cordova is not defined
ionic-core.js:466 Ionic Core: init
ionic-core.js:145 Ionic Core: searching for cordova.js
ionic-core.js:149 Ionic Core: cordova.js has already been loaded

Now this is making me confused but I assume that Ionic is trying to load cordova before it is defined. However, this prevents me from using other services that rely on this condition, so my question is, is there a way to load cordova async or what else might be my problem?

index.html

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/angular-websocket/angular-websocket.js"></script>
<script src="lib/ionic-service-core/ionic-core.js"></script>
<script src="lib/ionic-service-push/ionic-push.js"></script>
<script src="lib/facebook-connect-plugin/index.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/utils.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

During the app running, this is what I get:

Uncaught ReferenceError: cordova is not defined
ionic-core.js:466 Ionic Core: init
ionic-core.js:145 Ionic Core: searching for cordova.js
ionic-core.js:149 Ionic Core: cordova.js has already been loaded

Now this is making me confused but I assume that Ionic is trying to load cordova before it is defined. However, this prevents me from using other services that rely on this condition, so my question is, is there a way to load cordova async or what else might be my problem?

index.html

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/angular-websocket/angular-websocket.js"></script>
<script src="lib/ionic-service-core/ionic-core.js"></script>
<script src="lib/ionic-service-push/ionic-push.js"></script>
<script src="lib/facebook-connect-plugin/index.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/utils.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
Share Improve this question asked Sep 24, 2015 at 16:32 lmenuslmenus 61310 silver badges27 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

ng-cordova uses cordova so it must be loaded later:

<script src="cordova.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.min.js"></script>

cordova's plugin is designed for native plaform. So running ionic in a browser will fail all the plugins. That's the story.

发布评论

评论列表(0)

  1. 暂无评论