Function
inject (name) ComputedDecorator public
Module:
ember/controller
Defined in packages/@ember/controller/index.ts:344
Available since v1.10.0
- 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 | |
1 2 3 4 5 6 7 |
import Controller, { inject as controller } from ' /controller'; export default class PostController extends Controller { posts; } |
Classic Class Example:
app/controllers/post.js | |
1 2 3 4 5 6 7 |
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.