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. I've searched through other posts but still cannot solve the problem. What am I doing wrong here?
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:
{
"programs": [{
"title": "MA History"
}, {
"title": "MA Biology"
}, {
"title": "MA Chemistry"
}, {
"title": "MA Classical Studies"
}, {
"title": "MA Liberal Arts"
}]
}
$scope.programs = data.programs;in your success callback, otherwise you would need to doprogram in programs.programsin yourngRepeat. Also you may need to parse the json string to an object,JSON.parse(data). As i do not know if angular does it automatically or not.