Reputation: 439
Just updated Ember to v1.13.5, and received this warning:
DEPRECATION: Controller#needs is deprecated, please use Ember.inject.controller() instead
Can't find the documentation yet on how to write the new syntax. Any suggestions on how to fix this warning would be appreciated.
Upvotes: 10
Views: 1795
Reputation: 11293
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')
});
Upvotes: 17
Reputation: 27399
Here is one simple example and this blog post talks more about the evolution from manual injection to "Ember.inject"
export default Ember.Controller.extend({
flashManager: Ember.inject.controller('flash-message'),
actions: {
upVote: function() {
// Do some voting
var flashManager = this.get('flashManager');
flashManager.pushMessage('error', 'Your vote does not count');
}
}
}
});
Upvotes: 6