2016-09-09 18 views
0

これは私が

Index.htmlと //参考に$をhttpでエラーを取得する必要があり、問題

である理由わかりませんファイル

<script src="common/services/common.services.js"></script> 
<script src="common/services/deviceService.js"></script> 

common.services.jsは//私は明らかに$ HTTPをためngResource/$リソースを使用していないよ、私はhttpproviderを使用する必要がありますか?問題はここにある

(function() { 
     "use strict"; 

angular 
    .module("common.services", // name of module 
    ["ngResource"]) // array that defines the dependencies (ngResource contains the $resource service) 
}()); 

...

deviceService.js

(function() { 
"use strict"; 

angular 
    .module("common.services") 
    .factory("deviceService", 
    ["$http",deviceService]); 

    function deviceService($http) { 

     function httpGetCost(cost, amount, $http) { 
      $http.get('../api/deviceEvents.json') 
      .then(function (result) { 
      //....... 
     } 

     return { outsideCall: httpGetCost } 
    } 

}()); 
  1. 私は本当にcommon.service.jsの確認を目的...
  2. ないんだけど
  3. httpproviderサービス参照を取得するには$ httpが必要ですか?
  4. 私は$ httpに正しく挿入されていません?
+1

$ httpを内部関数httpGetcost()に渡すべきではないと思います。それを試してみることができますか? – SanketR

答えて

1

$httpを適切に注入しなかったため、わずかな構文エラーです。

(function() { 
    "use strict"; 

    angular 
     .module("common.services") 
     .factory("deviceService", ["$http", deviceService]); 

    function deviceService($http) { //this is the real $http that gets injected 

     function httpGetCost(cost, amount) { //remove your $http here 
     $http.get('../api/deviceEvents.json') 
      .then(function(result) { 
       //....... 
      } 

      return { 
       outsideCall: httpGetCost 
      } 
      } 

     }()); 
+0

ああ、なぜ内部機能のケアが必要なのでしょうか... –

+0

この$ httpBackendで素晴らしいです。私は勝てることはできませんが、そのエラーを過ぎていますが、それ以上のリクエストは期待できません $ httpBackend(angular-mocks.js:1418) –

関連する問題