$http.get(url) 读取服务器数据。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="//apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div ng-app="xxApp" ng-controller="xxCtrl">
<ol>
<li ng-repeat="x in names">
{{ x.Name + ', ' + x.City + ', ' + x.Country }}
</li>
</ol>
</div>
<script>
var app = angular.module('xxApp', []);
app.controller('xxCtrl', function($scope, $http) {
$http.get("/xxJSON.php")
.success(function (response) {
//从服务端引入JSON数据,$scope.names变成一个数组
$scope.names = response.records;
});
});
</script>
</body>
</html>
xxJSON.php
{"records":[
{
"Name" : "YY",
"City" : "Beijing",
"Country" : "China"
},
{
"Name" : "FF",
"City" : "Chengdu",
"Country" : "China"
},
{
"Name" : "LL",
"City" : "Shanghai",
"Country" : "China"
}
]}
输出: