Ember Inject Controller

October 09, 2015

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’)
> });_

Profile picture

Experience in software development, application architecture, and deploying cloud solutions for enterprise customers. Strong hands-on skills with a Master's degree in Computer Science and business acumen with a master of business administration (MBA) in Finance. Certified in Amazon Web Services (AWS), Google Cloud Platform (GCP), Microsoft Azure, Kubernetes (CKA, CKAD, CKS, KCNA) and Scrum (PSM, PSPO) with experience in building banking products from scratch. Connect on Linkedin

© 2022, @victorleungtw