Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialise controller state in EmberJs: Route#setupController vs Controller#init

There appear to be two alternative ways to set the initial state of a controller in EmberJs:

  • Route#setupController
  • Controller#init

When is it appropriate to use one over the other? Are they equivalent?

like image 391
bguiz Avatar asked Dec 17 '25 13:12

bguiz


1 Answers

Generally speaking, Controller#init gets called only once when the (usually singleton) controller is created, while Route#setupController is called each time the route is entered.

Any model-related properties should be set from Route#setupController. Other default setup can be handled in Controller#init.

In most Ember apps I have worked on, Route#setupController is used more often than Controller#init.

like image 80
Luke Melia Avatar answered Dec 20 '25 01:12

Luke Melia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!