Ember Inject Controller

October 09, 2015

The Problem I Encountered:

2015 10 10

After updating my Ember project to version 1.13.5, I received the following warning in the browser console:

_DEPRECATION: Controller#needs is deprecated. Please use Ember.inject.controller() instead._

However, I couldn't find any documentation on how to implement the new syntax.

The Solution:

Though it's marked as a private method in the Ember documentation, you can view it by selecting the "private" checkbox.

There are two ways to use Ember.inject.controller(): with and without specifying a controller name.

_App.PostController = Ember.Controller.extend({ posts: Ember.inject.controller() });_

When you don't specify the name of the controller, Ember uses the property name to look it up, as in:

posts: Ember.inject.controller('posts').

You will only need to specify the controller name if the property name and the controller name are different.

_App.PostController = Ember.Controller.extend({ myPosts: Ember.inject.controller('posts') });_

This way, you can successfully update your project to comply with the new Ember guidelines.

Profile picture

Victor Leung, who blog about business, technology and personal development. Happy to connect on LinkedIn