1.html页面
<body ng-app="myApp" ng-cloak>
<form id="form1" runat="server">
<div ng-controller="myController">
<ul>
<li ng-repeat="item in Users">{{item.name}}|{{item.gender}}
</li>
</ul>
</div>
</form>
</body>
2.javascript代码
var myApp = angular.module("myApp", []);
//myApp.value("BaseSource", {
// Users: [
// { "isBonusPoints": true, "name": "小芳", "likesubject": 2, "gender": 2, "integral": 100, "bonusPoints": 5 },
// { "isBonusPoints": true, "name": "小明", "likesubject": 1, "gender": 1, "integral": 111, "bonusPoints": 5 },
// { "isBonusPoints": false, "name": "小张", "likesubject": 2, "gender": 1, "integral": 98, "bonusPoints": 0 }
// ]
//});
myApp.service("Users", function () {
this.GetUser = function ($scope, $http) {
$http({
method: 'get', //get/post都可以
url: 'WebForm1.aspx?Type=1'
}).success(function (req) {
$scope.Users = req;
console.log(req);
})
}
});
myApp.controller("myController", ["$scope", "$http", "BaseSource", "Users", function ($scope, $http, BaseSource, Users) {
//$scope.Users = BaseSource.Users;
Users.GetUser($scope, $http);
}]);
3.后台获取数据
if (Request["Type"] == "1") {
string ResSource = "[{ \"isBonusPoints\": true, \"name\": \"小芳1\", \"likesubject\": 2, \"gender\": 2, \"integral\": 100, \"bonusPoints\": 5 },{ \"isBonusPoints\": true, \"name\": \"小明\", \"likesubject\": 1, \"gender\": 1, \"integral\": 111, \"bonusPoints\": 5 }, { \"isBonusPoints\": false, \"name\": \"小张\", \"likesubject\": 2, \"gender\": 1, \"integral\": 98, \"bonusPoints\": 0 } ]";
Response.Write(ResSource);
Response.End();
}