Services in AngularJS
Service in AngularJS is the functional block for providing data to components(controllers, services, filters or directives) across your app. You can write your own services. You can also use the built-in services in AngularJS, like $http. To use a service, you need to add it as a dependency for your component.
The steps for creating and using a service are as follows:
- Creating a service
- Using a service
You can also use the method factory
to register a service as follows:
As I said, you can also use many of the AngularJS built-in services. The ones you may use frequently are $http
, $q
, $animate
, $log
, $timeout,
$window and
$rootScope`, etc..