Use a Custom Service Inside a Filter
Once we created a service, and connected it to our application,
we use the service in any controller, directive, filter, or even inside other services.
To use the service inside a filter, add it as a dependency when defining the filter:
To create your own service, connect your service to the module:
Let's understand with an example
A custom service with a method:
1.They contain methods that maintain data throughout the life of an application,
i.e. data does not get refreshed and is available all the time.
2.The main objective of a service is to organize and share business logic, models,
or data and functions with different components of an Angular application.
3.For many services, like the $location service, it seems like you could use objects
that are already in the DOM, like the window.location object, and you could, but it
would have some limitations, at least for your AngularJS application.
4.AngularJS constantly supervises your application, and for it to handle
changes and events properly, AngularJS prefers that you use the $location service instead of the window.location object.
The $http Service
The $http service is used to send or receive data from the remote server using browser's XMLHttpRequest or JSONP.