Ember Controller vs Ember ArrayController

I don't understand when to use Ember.Controller

and when to use Ember.ArrayController

and its use.

+3


source to share


1 answer


With a controller, you can do {{#each item in model}}

in your template.

With ArrayController, you can just do {{#each item}}

.

Can. ArrayController is deprecated because it hides logic, you should never use it. The controller has also been deprecated in favor of routable components, somewhere in Ember 2.1 or 2.2.



The current strategy is:

  • Forget ArrayController, ObjectController and View.
  • Use ingredients for everything.
  • Before Ember 2.1 / 2.2, you cannot use a component for the root template of any route. You will have to use a controller for this template.
  • Don't put any logic into this controller. Just put the component in your template and pass the model. Use such controllers only for query parameters and other components that components are unable to (yet).
  • Do not use in routes setupController

    . Instead, put everything in a model, turning it into a hash of models. RSVP.hash

    - your friend.
  • When available routing components are available, replace the controllers with components.

PS The syntax for each

changes to {{#each model as |item|}}

.

+5


source







All Articles