The Problem I Encountered: Welcome to Continuous Improvement, the podcast where we explore solutions to common problems faced by developers. I’m your host, Victor, and today we are diving into a recent problem I encountered while updating my Ember project.

So, after updating to version 1.13.5, I was greeted with a warning in the browser console telling me that Controller#needs is deprecated. The warning kindly suggested that I should use Ember.inject.controller() instead. But, I was left wondering, how exactly do I implement this new syntax?

Luckily, I did some digging and found a solution that I’ll be sharing with you today. Firstly, let’s address the Ember documentation - it marks Ember.inject.controller() as a private method. But fear not, you can still access it by selecting the “private” checkbox. It’s always helpful to have access to these hidden gems, isn’t it?

Now, let’s dive into the implementation. There are actually two ways to use Ember.inject.controller(). The first method is without specifying a controller name. For example, you can define it like this:

Victor (cont.): App.PostController = Ember.Controller.extend({ posts: Ember.inject.controller() });

What happens here is that Ember uses the property name, in this case ‘posts’, to look up the controller. So, whenever you access ‘this.posts’ in your code, Ember will automatically fetch the ‘posts’ controller for you.

But what if the property name and controller name are different? Well, that’s where the second method comes in. You can specify the controller name using Ember.inject.controller(). For example:

Victor (cont.): App.PostController = Ember.Controller.extend({ myPosts: Ember.inject.controller('posts') });

Here we have ‘myPosts’ as the property name and ‘posts’ as the controller name. Now, whenever you access ‘this.myPosts’, Ember will fetch the ‘posts’ controller for you.

And there you have it - a solution to the deprecation warning you may face when updating your Ember project. By using Ember.inject.controller(), you can ensure your code complies with the latest Ember guidelines.

That’s it for today’s episode of Continuous Improvement. I hope this solution helps you tackle any similar issues you may encounter in your own projects. Remember, continuous improvement is the key to becoming a better developer.

If you have any questions or topics you’d like us to explore in future episodes, feel free to reach out to us. Thank you for tuning in, and until next time, keep coding and keep improving.