CordovaHTTP未捕获错误:[$ injector:modulerr](Ionic + AngularJS)
问题描述:
我正在使用AngularJS框架开发Ionic的应用程序。我需要所以我用cordovaHTTP插件(https://github.com/wymsee/cordova-HTTP,我最近用于的PhoneGap项目)运行下面的行
cordova plugin add cordova-plugin-http
当我尝试运行我的应用程序与服务器进行交互,显示了这个错误
Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to:
Error: [$injector:modulerr] Failed to instantiate module cordovaHTTP due to:
Error: [$injector:nomod] Module 'cordovaHTTP' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.4.3/$injector/nomod?p0=cordovaHTTP
at http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:13380:12
at http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:15270:17
at ensure (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:15194:38)
at module (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:15268:14)
at http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:17674:22
at forEach (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:13648:20)
at loadModules (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:17658:5)
at http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:17675:40
at forEach (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:13648:20)
at loadModules (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:17658:5)
http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=cordovaHTTP&p1=Erro…t%3A63342%2FaulasQR%2Fwww%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17658%3A5)
at http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:13380:12
at http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:17697:15
at forEach (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:13648:20)
at loadModules (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:17658:5)
at http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:17675:40
at forEach (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:13648:20)
at loadModules (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:17658:5)
at createInjector (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:17584:11)
at doBootstrap (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:14942:20)
at bootstrap (http://localhost:63342/aulasQR/www/lib/ionic/js/ionic.bundle.js:14963:12)
http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=starter&p1=Error%3A…%3A63342%2FaulasQR%2Fwww%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A14963%3A12)(anonymous function) @ ionic.bundle.js:13380(anonymous function) @ ionic.bundle.js:17697forEach @ ionic.bundle.js:13648loadModules @ ionic.bundle.js:17658createInjector @ ionic.bundle.js:17584doBootstrap @ ionic.bundle.js:14942bootstrap @ ionic.bundle.js:14963angularInit @ ionic.bundle.js:14857(anonymous function) @ ionic.bundle.js:41671trigger @ ionic.bundle.js:16308eventHandler @ ionic.bundle.js:16583
以我app.js文件I定义如下
qrApp = angular.module('starter', ['ionic', 'starter.controllers', 'starter.services','ngCordova', 'cordovaHTTP'])
同样在该文件中的模块,我声明为服务器的控制器(带有一个基本的例子)
.controller("serverController", function($cordovaHTTP){
var getData = function(uri){
var username = "yyy";
var password = "xxx";
var url = "http://movilesbluetooth.php.info.unlp.edu.ar/alumnos/1";
cordovaHTTP.useBasicAuth(username,password);
cordovaHTTP.get(url).then(function(response) {
alert(response.data);
$scope.response_data = response.data;
});
}
});
任何解决方案?
答
这不是$cordovaHTTP
只是cordovaHTTP
在控制器中。
答
Finnaly我可以解决这个问题tring手动引导我的应用程序。 在此之后的步骤:进的index.html index.html的
添加此的
- 删除 “NG应用内”
变种pgapp = { 初始化:功能(){ 控制台。日志(“adentro de init”); this.bindEvents(); },
// Bind any events that are required on startup. Common events are: // 'load', 'deviceready', 'offline', and 'online'. bindEvents: function() { console.log("adentro de bind"); document.addEventListener('deviceready', this.onDeviceReady, false); }, onDeviceReady: function() { console.log("adentro de device"); angular.element(document).ready(function() { angular.bootstrap(document, ['starter']); }); } }; </script>
,并在年底
<script type="text/javascript">
pgapp.initialize();
</script>
</body>
</html>
我知道,我改变了它来证明这一点,我又忘了更改。但也与“cordovaHTTP”我有同样的问题。 –
它不起作用 –
其他人在离子进入图片时也会遇到这个问题。尝试手动引导cordova以延迟ng-app初始化。看到这个链接https://github.com/wymsee/cordova-HTTP/issues/22 –