AngularJS-Common Services

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.