如何通过 Angularjs $http get req 从 JSON 文件访问数据?
How to access data from JSON file though Angularjs $http get req?
15.html
<html>
<meta charset="utf-8">
<title>Angularjs htttp services</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js">
</script>
<script src="controller15.js"></script>
</head>
<body ng-app="mainApp">
<div ng-controller="people">
<ul>
<h2> names and ages of the programmers</h2>
<li ng-repeat="person in persons">
{{ person.Name +':' +person.Age}}
</li>
</ul>
</div>
</body>
</html>
controller15.js
var app=angular.module('mainApp',[]);
app.controller('people', function($scope,$http)
{
$http.get('database.json')
.success(function(response)
{
$scope.person=response.records;
});
});
database.json 我存储信息的位置:
{
"records":[
{
"Name":"mehul","Age":"13"
},
{
"Name":"ashok","Age":"23"
},
{
"Name":"rajesh","Age":"44"
}
]
}
我已附上所有代码,请查看我的代码。我是 angularjs 的初学者;如果您建议我浏览一个特定的 material 或网站,那总是好的。
首先:不要使用angular的缩小版本来查看描述的错误
你的浏览器控制台。然后告诉我你看到了什么错误!
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js">
15.html
<html>
<meta charset="utf-8">
<title>Angularjs htttp services</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js">
</script>
<script src="controller15.js"></script>
</head>
<body ng-app="mainApp">
<div ng-controller="people">
<ul>
<h2> names and ages of the programmers</h2>
<li ng-repeat="person in persons">
{{ person.Name +':' +person.Age}}
</li>
</ul>
</div>
</body>
</html>
controller15.js
var app=angular.module('mainApp',[]);
app.controller('people', function($scope,$http)
{
$http.get('database.json')
.success(function(response)
{
$scope.person=response.records;
});
});
database.json 我存储信息的位置:
{
"records":[
{
"Name":"mehul","Age":"13"
},
{
"Name":"ashok","Age":"23"
},
{
"Name":"rajesh","Age":"44"
}
]
}
我已附上所有代码,请查看我的代码。我是 angularjs 的初学者;如果您建议我浏览一个特定的 material 或网站,那总是好的。
首先:不要使用angular的缩小版本来查看描述的错误 你的浏览器控制台。然后告诉我你看到了什么错误!
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js">