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://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></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)