AngularJS-Common Services
Angular has many built-in services, such as the $ location service, used to interact with the address bar of the browser; $ root service, used to switch views based on URL address changes; and $ http service, used to interact with the server.
$ RouteProvider
Use $ routeProvider to bind a route and view.
The routing service can be used to define a specific URL that the browser directs to. Angular loads and displays a template and instantiate a controller to provide content for the template.
How to switch the view: Angular initiates a request:
XHR: SmlHttpRequest, essentially Ajax.
$ Http. get (url): get the url and return it.
JSON data
| Name |
City |
Country |
| {X. Name }} |
{X. City }} |
{X. Country }} |
<Script> function customersController ($ scope, $ http) {$ http. get ("http://www.w3cschool.cc/try/angularjs/data/Customers_JSON.php") // This http request returns plain text with json content. . Success (function (response) {$ scope. names = response;}); // response is data in json format, which is equivalent to deserializing json as a js object. } </Script> <script src = "http://apps.bdimg.com/libs/angular.js/1.2.15/angular.min.js"> </script>
$ For the json content obtained by http, see:
[ { "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" } ]
Webpage Effect