在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ HTML/ AngularJS Ajax
AngularJS國際化
AngularJS表達(dá)式
AngularJS控制器
AngularJS MVC體系結(jié)構(gòu)
AngularJS表單
AngularJS服務(wù)
AngularJS作用域
AngularJS快速入門
AngularJS包括
AngularJS第一個應(yīng)用程序
AngularJS HTML DOM
AngularJS過濾器
AngularJS模塊
AngularJS Ajax
AngularJS自定義指令
AngularJS教程
AngularJS依賴注入
AngularJS表格
AngularJS指令
AngularJS環(huán)境設(shè)置
AngularJS視圖

AngularJS Ajax

AngularJS提供$http控制,可以作為一項服務(wù)從服務(wù)器讀取數(shù)據(jù)。服務(wù)器可以使一個數(shù)據(jù)庫調(diào)用來獲取記錄。 AngularJS需要JSON格式的數(shù)據(jù)。一旦數(shù)據(jù)準(zhǔn)備好,$http可以用以下面的方式從服務(wù)器得到數(shù)據(jù)。

function studentController($scope,$http) {
var url="data.txt";
   $http.get(url).success( function(response) {
                           $scope.students = response; 
                        });
}

在這里,data.txt中包含的學(xué)生記錄。 $http服務(wù)使Ajax調(diào)用和設(shè)置針對其學(xué)生的屬性。 “學(xué)生”模型可以用來用來繪制 HTML 表格。

例子

data.txt
[
{
"Name" : "Mahesh Parashar",
"RollNo" : 101,
"Percentage" : "80%"
},
{
"Name" : "Dinkar Kad",
"RollNo" : 201,
"Percentage" : "70%"
},
{
"Name" : "Robert",
"RollNo" : 191,
"Percentage" : "75%"
},
{
"Name" : "Julian Joe",
"RollNo" : 111,
"Percentage" : "77%"
}
]
testAngularJS.html
<html>
<head>
<title>Angular JS Includes</title>
<style>
table, th , td {
  border: 1px solid grey;
  border-collapse: collapse;
  padding: 5px;
}
table tr:nth-child(odd) {
  background-color: #f2f2f2;
}
table tr:nth-child(even) {
  background-color: #ffffff;
}
</style>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app="" ng-controller="studentController">
<table>
   <tr>
      <th>Name</th>
      <th>Roll No</th>
	  <th>Percentage</th>
   </tr>
   <tr ng-repeat="student in students">
      <td>{{ student.Name }}</td>
      <td>{{ student.RollNo }}</td>
	  <td>{{ student.Percentage }}</td>
   </tr>
</table>
</div>
<script>
function studentController($scope,$http) {
var url="data.txt";
   $http.get(url).success( function(response) {
                           $scope.students = response;
                        });
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
</body>
</html>

輸出

要運(yùn)行這個例子,需要部署textAngularJS.html,data.txt到一個網(wǎng)絡(luò)服務(wù)器。使用URL在Web瀏覽器中打開textAngularJS.html請求服務(wù)器??吹浇Y(jié)果如下:

AngularJS HTTPReqest