6

There are

  • controllers
  • constants
  • directives
  • services
  • factory
  • run
  • config
  • filters

functions of angular.js. What is the calling order of all these modules?

Blue
  • 22,608
  • 7
  • 62
  • 92
Sunil Garg
  • 14,608
  • 25
  • 132
  • 189

1 Answers1

16

Learning this I made a fiddle observing the behaviour by console.log. Its like

  • app config
  • app run
  • directive setup
  • directive compile
  • (app controller dependencies)
    • service
    • factory
    • inner factory
    • inner service
  • app controller
  • filter
  • directive linking
  • filter render (w.r.t the markup)

Observe yourself here (Check Console).

EDIT

New Fiddle with filters added

M. Junaid Salaat
  • 3,765
  • 1
  • 23
  • 25
  • and filters place? – Sunil Garg Jul 14 '16 at 12:39
  • @SunilGarg Please check the updated answer. I've added a filter too. – M. Junaid Salaat Jul 14 '16 at 12:53
  • thanks! but if i am injecting filter in the controller then the filter will get loaded first. Same with the service, if inject service in run then this will get loaded before run method. – Sunil Garg Jul 14 '16 at 17:41
  • Yes basically after `directive compile` the controllers dependencies are loaded and then the services factories filters get loaded w.r.t the dependencies which are injected in the controller. – M. Junaid Salaat Jul 15 '16 at 05:13
  • Will this order be maintained no matter the order in wich the programmer calls these functions ? – Xsmael Jan 17 '18 at 03:39
  • where does components come in this order ? Angular Js 1.5 has components ! – spacedev Apr 02 '18 at 09:37
  • 1
    Just to add: App Constant Providers, App Value Providers are executed in same order before App config is executed – Peter Parker May 29 '18 at 14:24
  • I downvote this as tthis answer is misleading... the documentation states clearly that provider functions are executed first (Value, Factory, Service, Provider, Constant) and then config and finally run blocks. You may notice that inside config or run blocks you can inject a service... that would be possible if config or run blocks are evaluated firsts. You may refer to https://docs.angularjs.org/guide/module#dependencies-and-order-of-execution – Victor Mar 27 '23 at 20:55
  • @Victor this is really an old answer. and i posted this answer while i was learning angularjs. I just demonstrated the behavior of angularjs with console.logs as you see above with fiddles. but maybe this is changed now but previous it worked like that – M. Junaid Salaat Mar 28 '23 at 21:46
  • @M.JunaidSalaat older or not people like me still find this and as long this content is reachable I guess you may amend it. Not my intention to be hard or anything, just trying to do a right thing. Greetings. – Victor Mar 29 '23 at 14:08