Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ember.js

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.

like image 666
Victor Leung Avatar asked Jul 24 '15 03:07

Victor Leung


People also ask

What is deprecation process?

Deprecation, in its programming sense, is the process of taking older code and marking it as no longer being useful within the codebase, usually because it has been superseded by newer code. The deprecated code is not immediately removed from the codebase because doing so may cause regression errors.

What is the use of @deprecated?

Using the @Deprecated Annotation To use it, you simply precede the class, method, or member declaration with "@Deprecated." Using the @Deprecated annotation to deprecate a class, method, or field ensures that all compilers will issue warnings when code uses that program element.

What does API deprecation mean?

A deprecated API is one that you are no longer recommended to use, due to changes in the API. While deprecated classes, methods, and fields are still implemented, they may be removed in future implementations, so you should not use them in new code, and if possible rewrite old code not to use them.

What does deprecated annotation do?

The @Deprecated annotation tells the compiler that a method, class, or field is deprecated and that it should generate a warning if someone tries to use it. That's what a deprecated class or method is. It's no longer relevant.


2 Answers

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')
});
like image 96
Patsy Issa Avatar answered Oct 29 '22 06:10

Patsy Issa


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');
    }
  }
}
});
like image 40
Toran Billups Avatar answered Oct 29 '22 04:10

Toran Billups