使用$http服务
$http服务也是一个公共服务,比较简单,直接上代码:
html
<html ng-app="MyModule">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="framework/angular-1.3.0.14/angular.js"><//script>
<script src="HTTPBasic.js"><//script>
</head>
<body>
<div ng-controller="LoadDataCtrl">
<ul>
<li ng-repeat="user in users">
{{user.name}}
</li>
</ul>
</div>
</body>
</html>
js
var myModule=angular.module("MyModule",[]);
myModule.controller('LoadDataCtrl', ['$scope','$http', function($scope,$http){
$http({
method: 'GET',
url: 'data.json'
}).success(function(data, status, headers, config) {
console.log("success...");
console.log(data);
$scope.users=data;
}).error(function(data, status, headers, config) {
console.log("error...");
});
}]);
data.json
[{
"name": "《用AngularJS开发下一代WEB应用》"
},{
"name": "《ORCHOME》"
},{
"name": "《ActionScript3.0》"
}]
这个不用说明了吧,跟jquery差不多。