Reputation: 103
I was wondering when exactly are Angular services initiated?
I am curious, because I think they (and the components) are initiated first, according to what I see in my app. Am I right?
Upvotes: 1
Views: 413
Reputation: 119
When Angular discovers that a component depends on a service, it first checks if the injector has any existing instances of that service. If a requested service instance doesn't yet exist, the injector makes one using the registered provider, and adds it to the injector before returning the service to Angular.
When all requested services have been resolved and returned, Angular can call the component's constructor with those services as arguments.
Upvotes: 3