0

app.run is supposed to be Angular's silbling to a Java main function. But is it mandatory or optional?

See also: AngularJS app.run() documentation?

Community
  • 1
  • 1
Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
  • it's optional, there are many cases where you won't need it. There is no such thing as a 'main' function in angularjs. – Josep Sep 25 '14 at 13:47
  • Just to clarify, *app.run()* does not run or start up your application, its just as @TomA said below. – m.e.conroy Sep 25 '14 at 13:53

1 Answers1

1

It is optional. Run blocks are effectively used for tasks that need to run before any other part of the app is injected or instantiated. If you don't have any of those requirements, you don't need a run block :)

Source - I've maybe written one, maybe two, run blocks for the multitude of angular projects I've worked on.

Edit: Run blocks won't run before EVERYTHING, they will run after config and service instantiation. Thanks to the comment below for pointing that out.

Tom A
  • 944
  • 1
  • 6
  • 16
  • 1
    Run block runs after all config phase is complete and the services are setup for DI. It's not guaranteed that it would run before other parts. – Chandermani Sep 25 '14 at 14:13