1, httpbasic.html:
<! DOCTYPE html>
<title> $http interacting with background data </title>
<meta charset= "Utf-8" >
<link rel= "stylesheet" href= ". /css/bootstrap.css ">
<script src= ". /js/angular.js "></script>
<body>
<div ng-controller= "Loaddatactrl" >
<ul>
<li ng-repeat= "User in Users" >
{{User.Name}}
</li>
</ul>
</div>
<script src= "Httpbasic.js" ></script>
</body>
2, Httpbasic.js:
var mymodule = angular.module ("App", []);
Mymodule.controller (' Loaddatactrl ', [' $scope ', ' $http ',
function ($scope, $http) {
$http ({
Method: ' GET ',
URL: ' Data.json '
}). Success (function (Data,status,header,config) {
Console.log (data);
$scope. Users = data;//is assigned directly to the users in Ng-repeat
}). Error (function (data,status,header,config) {
Console.log ("error ...");
});
}]);
3. Background data file--data.json
[{
"Name": "Development of next-generation Web applications with Angularjs"
},{
"Name": "Ext Lake"
},{
"Name": "The authoritative guide of Angularjs"
}]
[email protected] $ HTTP service interacts with background data