AngularJS Tutorial(7)from w3school
来源:互联网 发布:网络流行语2016英文 编辑:程序博客网 时间:2024/06/01 08:21
$http is an AngularJS service for reading data from remote servers.
Providing Data
The following data can be provided by a web server:
http://www.w3schools.com/angular/customers.php
"records": [
{
"Name" : "Alfreds Futterkiste",
"City" : "Berlin",
"Country" : "Germany"
},
{
"Name" : "Berglunds snabbköp",
"City" : "Luleå",
"Country" : "Sweden"
},
{
"Name" : "Centro comercial Moctezuma",
"City" : "México D.F.",
"Country" : "Mexico"
},
{
"Name" : "Ernst Handel",
"City" : "Graz",
"Country" : "Austria"
},
{
"Name" : "FISSA Fabrica Inter. Salchichas S.A.",
"City" : "Madrid",
"Country" : "Spain"
},
{
"Name" : "Galería del gastrónomo",
"City" : "Barcelona",
"Country" : "Spain"
},
{
"Name" : "Island Trading",
"City" : "Cowes",
"Country" : "UK"
},
{
"Name" : "Königlich Essen",
"City" : "Brandenburg",
"Country" : "Germany"
},
{
"Name" : "Laughing Bacchus Wine Cellars",
"City" : "Vancouver",
"Country" : "Canada"
},
{
"Name" : "Magazzini Alimentari Riuniti",
"City" : "Bergamo",
"Country" : "Italy"
},
{
"Name" : "North/South",
"City" : "London",
"Country" : "UK"
},
{
"Name" : "Paris spécialités",
"City" : "Paris",
"Country" : "France"
},
{
"Name" : "Rattlesnake Canyon Grocery",
"City" : "Albuquerque",
"Country" : "USA"
},
{
"Name" : "Simons bistro",
"City" : "København",
"Country" : "Denmark"
},
{
"Name" : "The Big Cheese",
"City" : "Portland",
"Country" : "USA"
},
{
"Name" : "Vaffeljernet",
"City" : "Århus",
"Country" : "Denmark"
},
{
"Name" : "Wolski Zajazd",
"City" : "Warszawa",
"Country" : "Poland"
}
]
}
AngularJS $http
AngularJS $http is a core service for reading data from web servers.
$http.get(url) is the function to use for reading server data.
AngularJS Example
<ul>
<li ng-repeat="x in names">
{{ x.Name + ', ' + x.Country }}
</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://www.w3schools.com/angular/customers.php")
.success(function(response) {$scope.names = response.records;});
});
</script>
Try it Yourself »
Application explained:
The AngularJS application is defined by ng-app. The application runs inside a <div>.
The ng-controller directive names the controller object.
The customersCtrl function is a standard JavaScript object constructor.
AngularJS will invoke customersCtrl with a $scope and$http object.
$scope is the application object (the owner of application variables and functions).
$http is an XMLHttpRequest object for requesting external data.
$http.get() reads JSON data from http://www.w3schools.com/angular/customers.php.
If success, the controller creates a property (names) in the scope, with JSON data from the server.
- AngularJS Tutorial(7)from w3school
- AngularJS Tutorial(1)from w3school
- AngularJS Tutorial(2)from w3school
- AngularJS Tutorial(3)from w3school
- AngularJS Tutorial(4)from w3school
- AngularJS Tutorial(5)from w3school
- AngularJS Tutorial(6)from w3school
- AngularJS Tutorial(8)from w3school
- AngularJS Tutorial(9)from w3school
- AngularJS Tutorial(10)from w3school
- AngularJS Tutorial(11)from w3school
- AngularJS Tutorial(12)from w3school
- AngularJS Tutorial(13)from w3school
- AngularJS Tutorial(14)from w3school
- AngularJS Tutorial(15)from w3school
- AngularJS Tutorial(16)from w3school
- AngularJS Tutorial(17)from w3school
- AngularJS Tutorial(18)from w3school
- 高效画圆角的方法
- AngularJS Tutorial(6)from w3school
- GdiplusFlat(4)单色画刷 和 线性渐变画刷
- PowerDesigner生成SQL脚本时,对象带有双引号的问题解决
- 32位和64位下Myeclipse、Tomcat以及JDK三者关系详解
- AngularJS Tutorial(7)from w3school
- AngularJS Tutorial(8)from w3school
- SPOJ COT 10628 Count on a tree
- 什么是好软件
- Objective-C中的一些特殊的数据类型
- AngularJS Tutorial(9)from w3school
- 智慧北京4
- MyEclipse 2015 反编译插件安装
- 0.0.0.0:80端口被占用解决方案