2015-04-22 67 views
-1

每當我試圖包括$ HTTP在我的js依賴,我得到有關$噴油器的錯誤:modulerr.My代碼如下所示:

angularEx.html

<!DOCTYPE html> 
<html ng-app="Fin"> 
    <head> 
    <link rel="stylesheet" type="text/css" href="scripts/bootstrap.min.css" /> 
    <script type="text/javascript" src="scripts/angular.min.js"></script> 
    <script src="bower_components/angular-route/angular-route.js"></script> 
    <script src="bower_components/angular-resource/angular-resource.js"></script> 
    <script type="text/javascript" src="scripts/app.js"></script> 
    </head> 
    <body> 

    <div ng-controller="PhoneController as phone"> 
    {{phone.products.subject}} 
    </div> 
</body> 
    </html> 

app.js

var app=angular.module('Fin',[]); 

app.controller('PhoneController',['$http',function('$http'){ 

    var store=this; 


    $http.get('/dell-streak-7.json').success(function(data){ 
     store.products=data; 
    }); 
}]); 

戴爾條紋7.json文件

{ 
    "subject": "Front Facing 1.3MP Camera", 

} 

輸出窗口:

enter image description here

enter image description here

回答

4

你去在引號clared的說法,所以它應該是:

['$http',function($http){}] 

代替:

['$http',function('$http'){ 
3

你的控制器定義是語法錯誤:

app.controller('PhoneController', ['$http', function('$http') { 

請注意,你有一個字符串($http )作爲函數參數。這實際上是第一條錯誤消息的原因,說「未捕獲的SyntaxError:意外的字符串」

下應該是正確的:

app.controller('PhoneController', ['$http', function($http) { 

其他錯誤(「$注射器:modulerr」)可能只是語法錯誤的一個重要的錯誤。

相關問題