Uuid
Uuid

Reputation: 2546

Execution order of services, factories & providers in AngularJS?

Does AngularJS framework executes all mentioned above in a predefined order or is this done by the programmer?

Upvotes: 3

Views: 2077

Answers (2)

holographic-principle
holographic-principle

Reputation: 19738

Providers and Constants are created during config phase, while Factories, Services and Values are created after the config stage (so you can't inject them into config).

There are no other fine-grain differences to my knowledge (meaning you can assume all the services -- and by this I mean any type of provider -- that you inject will be available to you)

Upvotes: 4

bellkev
bellkev

Reputation: 925

In terms of terminology, factories can generate services, and providers provide services to components that request them. If some of your services depend on other service, then there should certainly be some alternative executing of services and providers. Making sure that all of these things happen in the right order to allow all the services to be instantiated is the job of Angular's dependency injection.

One question to ask is, why do you care what order the factory functions run in? If you declare your dependencies correctly and your services are appropriately un-coupled, Angular should take care of things for you. The only exotic case you might run into is a circular dependency, which you can see some discussion of here.

Upvotes: 3

Related Questions