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/

1 Like

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.

2 Likes

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

  1. The guides still recommend using controllers for query parameters: Query Parameters - Routing - Ember Guides
  2. searching for ‘controllers dead’ on the slack channel: Slack
  3. Folks in that channel link to this article to explain more: Controllers are dead; Long live Controllers. @jobsboris27 that article provides a fairly concise summary.

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

1 Like