The service will helps to fetch data from the database when to share the data between controllers.
If we store the data inside a controller, once we change to another controller the data will be discarded.
AngularJS has 30 built in services.
Types of Services in AngularJS
-
Built-in Services: The angularjs has inbuilt services. That’s is core services.
The built in services like $http, $log, $location etc..
The inbuilt services are always prefixed with $. - Custom Services: These services are developed by developers to achieve certain business logic in the form of service.
The $http Service
The $http is the one of the inbult services in angularjs. It is commonly used services in angularjs application.
Example
Use the $http service to request data from the server:
Today's welcome message is:
{{myWelcome}}
From the above code we can clearly say that: The $http service requests a page on the server, and the response is set as the value of the “myWelcome” variable.
The $location Service
The $location service has methods which return information about the location of the current web page:
Example
The url of this page is:
{{myUrl}}