每当我尝试在我的js中包含$ http依赖项时,我收到与$ injector:modulerr相关的错误。我的代码如下所示:
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;
});
}]);
dell-streak-7.json文件
{
"subject": "Front Facing 1.3MP Camera",
}
输出窗口:
答案 0 :(得分:4)
你用引号声明了参数,所以它应该是:
['$http',function($http){}]
代替:
['$http',function('$http'){
答案 1 :(得分:3)
您的控制器定义在语法上是错误的:
app.controller('PhoneController', ['$http', function('$http') {
请注意,您有一个字符串文字($http
)作为函数参数。这实际上是第一条错误消息的原因,该消息显示“Uncaught SyntaxError:Unexpected String”
以下内容应该是正确的:
app.controller('PhoneController', ['$http', function($http) {
另一个错误(“$ injector:modulerr”)可能只是语法错误的重大错误。