Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember Controller vs Ember ArrayController

I don't get a clear difference as to when to use Ember.Controller and when to use Ember.ArrayController and its usage.

like image 782
Neovire Avatar asked Jun 08 '26 19:06

Neovire


1 Answers

With a Controller, you could do {{#each item in model}} in your template.

With ArrayController, you could simply do {{#each item}}.

Could. ArrayController is deprecated because it was obscuring the logic, you should never use it. The Controller is also being deprecated in favor of routeable components, somewhere in Ember 2.1 or 2.2.

Current strategy is the following:

  • Forget ArrayController, ObjectController and View.
  • Use components for everything.
  • Until Ember 2.1/2.2, you're unable to use a component for a root template of any route. For that template, you'll have to use a controller.
  • Don't put any logic into that controller. Simply place a component in its template and pass the model through. Use such controllers only for query params and other stuff that components are incapable of (yet).
  • In routes, don't use setupController. Instead, put everything into a model, turning it into a hash of models. RSVP.hash is your friend.
  • When routable components are available, replace controllers with components.

PS The syntax for each is changing to {{#each model as |item|}}.

like image 154
Andrey Mikhaylov - lolmaus Avatar answered Jun 10 '26 09:06

Andrey Mikhaylov - lolmaus



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!