I have declared the provider of my of service just narrowly in the metadata of the creator of my component,
instead of doing this into the app module, that looks like the recommended way.
OK, this is not something very specific of components, but I'm going to explain you briefly, which
is the difference, your neighbor instantiating the components you never call new time a component.
It is angular.
That that's nice for you.
If the constructor of the component includes one service like this name or service, then Angular needs
to have an instance of this service in order to persuade the constructor of the component.
And that's what I need you to declare the provider of the component somewhere.
It doesn't matter if you do it on the main module or in the component, but then we learned to understand
how to instantiated in order to use the dependency injection.
Anyway, the question is that services are singletons.
So if you need the service to communicate between several components, it makes a lot of sense to declare
your provider at the module level because that way they will share the instance.
However, when the service is at all of your component, you will probably need to declare it at the
component level.
So the instance does not get shared between components, ok.
It will be easier than to start with an example.
So I will make three more times I move to app component HDMI.
Copy this, I repeat it twice and then end with different start times.
So now I have three components, and what I'm going to do is to change how the provider is the client
and I'm going to declare it at the module level.
So al-Bashir my time of service, I also import it and they have to remove it from the component side.
So I remove directly this provider's here.
And right now this means that I'm not passing the provider at the component level, but at the main
module level.
So what's the result?
I move to the browser to see my terminals and you can see that all of them have exactly the same start
time.
But remember that the end times are completely different.
All of them have one five seconds.
That equals three minutes, five seconds.
Also said that the actions they do on one component are being applied to all of them.
So I can come here.
Was it imposing all of them or click restart and then restarting all of them?
And that's because right now all of the components are sharing the same instance of my time and service.
However, if I go back to code and they undo all the changes I have recently done, so I implore the
provider at the component level.
I can go back to see the results and I can see here all the time with the different any time.
And if I click on one, it starts to count them without affecting the rest.
So as you can see, all of them can work separately without interfering each other, because in this
case, each time a component has its own instance of the service.