As
we saw in the previous posts AngularJS
services are singleton objects / functions which are defined once and re-used throughout the application.
AngularJS provides a pre-defined set of services which we can reference in our controller and use the methods in the services, the pre-defined services are always pre-fixed with a $ symbol. $http, $window, $routeProvider etc are some of the pre-defined services provided by AngularJS.
AngularJS also allows us to define our own services and use them in the controllers and views, we can create the following 3 types of custom services in AngularJS
1) Service
Behaves like a static class in C#, when a function in the service is called, it executes the function and returns the function output to the controller.
2) Factory
More flexible than the service, allows us to define our own object and return the object to the calling controller.
3) Provider
The Provider service is a more complex version of the factory service implementation, it allows us to define and use configuration options while defining the service.
AngularJS provides a pre-defined set of services which we can reference in our controller and use the methods in the services, the pre-defined services are always pre-fixed with a $ symbol. $http, $window, $routeProvider etc are some of the pre-defined services provided by AngularJS.
AngularJS also allows us to define our own services and use them in the controllers and views, we can create the following 3 types of custom services in AngularJS
1) Service
Behaves like a static class in C#, when a function in the service is called, it executes the function and returns the function output to the controller.
2) Factory
More flexible than the service, allows us to define our own object and return the object to the calling controller.
3) Provider
The Provider service is a more complex version of the factory service implementation, it allows us to define and use configuration options while defining the service.
No comments:
Post a Comment