2016-03-01 111 views
0

我正在使用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; 
      }); 

    } 

    }); 

任何解決方案?

回答

1

這不是$cordovaHTTP只是cordovaHTTP在控制器中。

+0

我知道,我改變了它來證明這一點,我又忘了更改。但也與「cordovaHTTP」我有同樣的問題。 –

+0

它不起作用 –

+0

其他人在離子進入圖片時也會遇到這個問題。嘗試手動引導cordova以延遲ng-app初始化。看到這個鏈接https://github.com/wymsee/cordova-HTTP/issues/22 –

0

Finnaly我可以解決這個問題tring手動引導我的應用程序。 在此之後的步驟:進的index.html index.html的

  • 添加此的

    1. 刪除 「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> 
    
  • 相關問題