[英]Questionwith AngularJS ng-repeat and json data
Being new to AngularJS it seems certain things should be simple but I reaching out for support on the correct way to retrieve json data using ng-repeat. 作为AngularJS的新手,似乎某些事情应该很简单,但我寻求使用ng-repeat检索json数据的正确方法的支持。 I've searched through other posts but still cannot solve the problem. 我搜索了其他帖子,但仍然无法解决问题。 What am I doing wrong here? 我在这里做错了什么?
html: HTML:
<html lang="en" ng-app="configApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Configuration Admin</title>
</head>
<body>
<div ng-controller="OrganizationProgramCtrl">
<ul>
<li ng-repeat="program in programs">{{programs.title}}</li>
</ul>
</div>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
<script>
var configApp = angular.module("configApp", []);
function OrganizationProgramCtrl($scope, $http) {
$scope.programs = [];
$http.get('data/programs.json')
.success(function (data, status, headers) {
console.log("Data Found");
$scope.programs = data;
});
}
</script>
</body>
</html>
json data: json数据:
{
"programs": [{
"title": "MA History"
}, {
"title": "MA Biology"
}, {
"title": "MA Chemistry"
}, {
"title": "MA Classical Studies"
}, {
"title": "MA Liberal Arts"
}]
}
You code needs a couple of changes but you're almost there: 您的代码需要进行一些更改,但是您几乎可以做到了:
$scope.programs = data.programs;
and (singular program for title 和(标题的单一程序
<li ng-repeat="program in programs">{{program.title}}</li>
Working reference version here: 这里的工作参考版本:
http://plnkr.co/edit/JwmmA5?p=preview http://plnkr.co/edit/JwmmA5?p=preview
In your ng-repeat you are assign the current iterator item to a variable called program
however in your html to are referencing {{programs.title}}
(programs with an 's') 在ng-repeat中,您将当前的迭代器项分配给一个名为program
的变量,但是在html中引用了{{programs.title}}
(带有's'的程序)
Change it to this and it should work {{program.title}}
更改为此,它应该可以工作{{program.title}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.