Interviews4 answers
What are role of services in Angular?
4 Answers
The service is used to serve the data.
Below are uses of services.
It can be connected to database through HttpClient
It can be served JSON Object .
It can be used for authentication.
Dharmendra PawarPosted Apr 29, 2018, 5:55 PM EDT
functions to access over the all controllers
t.santosh raoPosted Apr 17, 2018, 9:18 PM EDT
Services are separation of concerns. It is a bridge between backend/server side components and UI components. You can use service as a plug and play component. This helps in making the project more testable as you have better mocking entry points. Also using the services you can make your angular component very light as you can load only services which are required for the component by injecting them in the constructor.
Asif KhanPosted Mar 13, 2018, 2:55 AM EDT
Basically, by the help of services, you can easily separation of your code which communicates with the database. Most of the method we used in services are directly talked to the database and fetch the data.
Now, this is reusable, you can inject this any of the component (if the version is greater than angular 1) and any of the controller (if the version is 1). One more important use of service is to pass data between controllers and components.
Mahesh VermaPosted Mar 12, 2018, 8:58 PM EDT



