- Making separation of concerns possible, i.e. the property of AngularJS. Some examples of the inbuilt Services are $https, $route, $location, $window etc.
- Let’s use an inbuilt Service to check what will be the benefit and how we can use the Services.
- We can create the Services, using three ways.
- By using Service method, we get an instance of a function passed to “module.service” and by using factory method, we get the value, which is returned by invoking the function reference, which is is passed to module.factory.
- In the article, we have seen how the Services can be created as per use and how can we use inbuilt Services.
This article is about Angular Services. This will give you a brief idea about Angular Services and how can we create our own services.
@CsharpCorner: Introduction To #AngularJS #Services by @IamJasbeerSingh cc @CsharpCorner #Framework #App
Let’s use an inbuilt Service to check what will be the benefit and how we can use the Services. Let’s use $location, $location is a Service that has methods, which returns information about the location of the current Webpage. Now, we will also see the use of dependency injection mechanism. The Service will be defined as a dependency.
Now, we will see how we can use them.
Let’s understand this with an example given below.
Now, we can see all the three ways. If we run this, we will get the output given below.