Ember controller - what is it?


I came in a new project, where people using Ember - 2.4.5 I worked in previous jobs in react.

How you are using controller, what is that? Guide in official site Ember generates more questions…


Basically, it is the Javascript behind a template. Any properties you use in your template, are the controller’s.

Components also have a template and a Javascript file: the idea is the same.

I voiced numerous times my desire for the concept of “controller” to be eliminated from Ember because it’s barely needed anymore and a source of confusion with beginners. Thank you for confirming my suspicion.

You may be interested in this: http://emberigniter.com/should-we-use-controllers-ember-2.0/


Components also have a template and a Javascript file: the idea is the same. I can create in componen.js custom logic for my component?


Basically, controllers are dead. They are an empty shell that only exists for legacy reasons, and you should not bother with them in a new project.

If your template uses any properties / state, they should be extracted into a component, and the template then just instanciates that component.


@spectras Controllers are still used/recommended for some things:

  1. The guides still recommend using controllers for query parameters: https://guides.emberjs.com/v2.6.0/routing/query-params/
  2. searching for ‘controllers dead’ on the slack channel: https://embercommunity.slack.com/archives/-help/p1465063860000210
  3. Folks in that channel link to this article to explain more: https://locks.svbtle.com/controllers-are-dead-long-life-controllers. @jobsboris27 that article provides a fairly concise summary.

It seems components will subsume aspects of controllers behavior. (TLDR ‘routeable components’ https://github.com/ef4/rfcs/blob/routeable-components/active/0000-routeable-components.md) IMHO asking here and in slack provides the most clarity on how controllers fit in the Ember 2.X programming model.