[MUSIC].
Let us now get a quick understanding of angular services.
What are they?
Why do we need them?
And how do they help in building our angular application?
The first question, why do we need services?
When we develop an angular repetition,
we want to keep our component classes as lean as possible.
They should be mainly concentrated on acting as the mediator between
the view and the application logic between the view and the model in some sense.
So this component would be providing a view
model like ability for our angular component.
So in the component classes we want to
delegate all the work of fetching data from the server.
Validating the user's input and logging information to a service.
So the service is a functionality that is available to provide these kind of
features that our component classes can leverage to get their work done.
So that is where the need for a service comes in.
So we try to factor out the application logic into services and let them do all
the heavy lifting of performing much of the application level logic,
and the services will take care of things like communicating with the server,
input validation and many other features.
In this context you will come across the term called dependency injection
which we will talk about in a little more detail.
Going back to that structure of our component,
we see that now we have the component and the template.
So the template taking care of rendering the view for
our component and the component itself managing the properties and
the matrix that will be leverage by the template for displaying the information.
Now, the component itself can then take the help of a service so
in this case the service will be injected into the component to provide
certain features for the component to make use of.
So the service takes care of doing all the work
behind the scenes that facilitates the component to be able to provide.
Well the properties and the methods for
the template to make use of while rendering the view.
And correspondingly, transporting the user interaction
related actions back to the model behind the scenes.
In the context of the service
you'll often here people also mentioning some related concepts.
Things like dependency injection
which we will talk about in little more detail later.
Then we'll also here people tak about promises.
We'll talk about promises in the next module.
I promise that.
And finally, you'll also hear
people talking about the use of reactive JavaScript.
Now, when we use service as a reactive JavaScript comes to or
help in accomplishing certain things.
So we'll also look at reactive JavaScript in the context of angular
in the next module.
Now that we have some basic understanding of services let's use them in our
application and then get to know services first hand by practicing,
implementing some services for our angle of application.
[MUSIC]