Kumar Gaurav
Kumar Gaurav

Reputation: 1327

Difference between Controller and Route in emberjs

This has been very confusing for me since I started using ember js. I am using ember js 2.11 (as shown in my package.json "ember-cli": "2.11.1")

I was trying to emit onClick action from my component to route and i got the error "An action named 'getDetails' was not found in generated controller" even when i had action named getDetails in my route.

I have read that with ember 2.0+ controller has been deprecated and route is made for the same purpose.

Please clarify.

Upvotes: 0

Views: 965

Answers (1)

zeppelin
zeppelin

Reputation: 1134

  1. Controllers are not yet deprecated. Use them as documented, once they do become deprecated, there will be a clear and painless upgrade path.
  2. When you send an action like {{action "getDetails"}} from a template that is not a component's template, the controller is the default action handler. The phrase generated controller in the error tells that you didn't create one, so Ember did the work for you by creating an anonymous controller. By definition, it has no actions, properties or anything. Create a controller, if you want to handle the action.
  3. Or, if you really want to handle the action on the route (or one of the parent routes), use the ember-route-action-helper addon.
  4. "ember-cli": "2.11.1" inside package.json only tells you the version of the Ember CLI (the command line interface), the Ember version is either "ember-source" inside the same file, or "ember" inside bower.json.

Hint: Read the guides carefully! :)

Upvotes: 3

Related Questions