Ember Inject Controller

The problem I got:

Just updated the Ember project to v1.13.5, and received this warning in brower console:

DEPRECATION: Controller#needs is deprecated, please use Ember.inject.controller() instead

However, I couldn’t find the documentation yet on how to write the new syntax.

Here is the Solution:

For some reason it’s marked as a private method in the docs, in order to see it you ll need to tick the private checkbox.

There are 2 ways to use it, with and without passing a controller name to it

App.PostController = Ember.Controller.extend({ posts: Ember.inject.controller()

When the name of the controller isn’t passed, ember uses the property name to look it up such as

posts: Ember.inject.controller(‘posts’).

You will only ever specify the controller name when the property and the controller have different names.

App.PostController = Ember.Controller.extend({ myPosts: Ember.inject.controller(‘posts’)

Originally published at victorleungtw.com on July 27, 2015.

By Victor Leung

Experience in software development, consulting services and technical product management. Understanding of business and technology with an MBA in Finance and a Master degree in Computer Science. AWS Certified Solution Architect with experience in building products from scratch and serving as a charismatic leader.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: