AngularJS Services (Service)

Source: Internet
Author: User

AngularJS You can create your own services, or use the built-in services.

What is a service?

In AngularJS, a service is a function or object that can be used in your AngularJS app.

More than 30 services are built in AngularJS.

There is a $location service that can return the URL address of the current page.

<!DOCTYPE HTML><HTML><Head>    <MetaCharSet= "Utf-8">    <Scriptsrc= "Http://"></Script></Head><Body>    <DivNg-app= "MYAPP"Ng-controller= "Myctrl">        <P>URL of the current page:</P>        <H3>{{Myurl}}</H3>    </Div>    <P>The instance uses the built-in $location service to get the URL of the current page. </P>    <Script>        varapp=Angular.module ('myApp', []); App.controller ('Myctrl', function($scope, $location) {$scope. Myurl=$location. Absurl ();    }); </Script></Body></HTML>

Note $location service is passed as a parameter to the controller. If you want to use it, you need to define it in the controller.

Why use the service?

$http is the most commonly used service in AngularJS applications. The service sends a request to the server to apply the data sent by the response server.

AngularJS Services (Service)

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: 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.