我正在使用AngularJS Framework在Ionic中开发应用程序。我需要与服务器进行交互,所以我使用了cordovaHTTP插件(https://github.com/wymsee/cordova-HTTP,我最近用于一个电话间隙项目)运行以下行
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文件中,我定义了一个像这样的模块
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;
});
}
});
任何解决方案?
答案 0 :(得分:1)
控制器中只有$cordovaHTTP
cordovaHTTP
。
答案 1 :(得分:0)
Finnaly我可以通过手动引导我的应用来解决这个问题。 按照以下步骤操作:
将其添加到index.html
var pgapp = { initialize:function(){ console.log(“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>