Javascript AngularJS http.get()访问json控制器
我是Javascript AngularJS http.get()访问json控制器,javascript,json,angularjs,Javascript,Json,Angularjs,我是AngularJS新手,一直在尝试使用$http方法解析json。我做了一个测试$scope.test=“working”;变量,工作正常。在输入我的$http方法代码后,它停止工作,$http方法也不工作。这是我的json: { "programmes":[ { "@attributes":{ "id":"1" }, "name":"Arrow", "imagepath":".
AngularJS
新手,一直在尝试使用$http
方法解析json
。我做了一个测试$scope.test=“working”;变量
,工作正常。在输入我的$http
方法代码后,它停止工作,$http
方法也不工作。这是我的json
:
{
"programmes":[
{
"@attributes":{
"id":"1"
},
"name":"Arrow",
"imagepath":"..\/img\/arrow.jpg"
},
{
"@attributes":{
"id":"2"
},
"name":"Fargo",
"imagepath":"..\/img\/fargo.jpg"
},
{
"@attributes":{
"id":"3"
},
"name":"You, me and the Apocalypse",
"imagepath":"..\/img\/youme.jpg"
},
{
"@attributes":{
"id":"4"
},
"name":"Heat",
"imagepath":"..\/img\/heat.jpg"
},
{
"@attributes":{
"id":"5"
},
"name":"The Thick of It",
"imagepath":"..\/img\/thick.jpg"
}
]
}
这是我的控制器文件:
app.controller('MainController', ['$scope', function($scope) {
$scope.test = "works";
$http.get("../../jsons/programmes.json").success(function(response) {$scope.programmes = response.programmes;});
}]);
最后,我的html:
<ul>
<li ng-repeat="x in programmes">
{{ x.name }}
</li>
</ul>
<p>{{test}}</p>
-
{{x.name}
{{test}}
因此,对于控制器中的
$http.get()
,{{test}}
会按字面意思显示出来,但当我删除它时,它会显示“works”。ng repeat
ul
根本不起作用。我做错了什么?您需要在控制器中注入$http angular服务。
您可以查看您的浏览器控制台。一般来说,它会提示你错过了什么
app.controller('MainController', ['$scope', '$http', function ($scope, $http) {
您看到的是angular表达式
{{test}
,因为缺少的依赖项会破坏控制器代码。您需要在控制器中注入$http angular服务。
您可以查看您的浏览器控制台。一般来说,它会提示你错过了什么
app.controller('MainController', ['$scope', '$http', function ($scope, $http) {
您看到的是角度表达式{{test}
,因为缺少的依赖项会破坏控制器代码