3

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

Uuid
  • 2,506
  • 5
  • 28
  • 37
  • I would guess it's an arbitrary topological sort based on the dependencies of the modules requested. – Jesus is Lord Aug 26 '13 at 18:41
  • See if this answer helps: ["angularJS $on event handler trigger order"](http://stackoverflow.com/a/17452084/1095616). – Stewie Sep 07 '13 at 13:00

2 Answers2

4

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)

holographic-principle
  • 19,688
  • 10
  • 46
  • 62
3

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.

bellkev
  • 915
  • 7
  • 10