Function

inject (name) ComputedDecorator public

Module: @ember/controller

Available since v1.10.0

import { inject } from '@ember/controller';
name
String
(optional) name of the controller to inject, defaults to the property's name
returns
ComputedDecorator
injection decorator instance

Creates a property that lazily looks up another controller in the container. Can only be used when defining another controller.

Example:

app/controllers/post.js
import Controller, {
  inject as controller
} from '@ember/controller';

export default class PostController extends Controller {
  @controller posts;
}

Classic Class Example:

app/controllers/post.js
import Controller, {
  inject as controller
} from '@ember/controller';

export default Controller.extend({
  posts: controller()
});

This example will create a posts property on the post controller that looks up the posts controller in the container, making it easy to reference other controllers.

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Fcontroller/inject