Class Ember.inject

public

Namespace for injection helper methods.

Show:

Module: ember

Available since v1.10.0

name
String
(optional) name of the controller to inject, defaults to the property's name
returns
Ember.InjectedProperty
injection descriptor instance

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

Example:

1
2
3
App.PostController = Ember.Controller.extend({
  posts: Ember.inject.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. This is functionally equivalent to:

1
2
3
4
App.PostController = Ember.Controller.extend({
  needs: 'posts',
  posts: Ember.computed.alias('controllers.posts')
});
Module: ember

Available since v1.10.0

name
String
(optional) name of the service to inject, defaults to the property's name
returns
Ember.InjectedProperty
injection descriptor instance

Creates a property that lazily looks up a service in the container. There are no restrictions as to what objects a service can be injected into.

Example:

1
2
3
4
5
6
7
App.ApplicationRoute = Ember.Route.extend({
  authManager: Ember.inject.service('auth'),

  model() {
    return this.get('authManager').findCurrentUser();
  }
});

This example will create an authManager property on the application route that looks up the auth service in the container, making it easily accessible in the model hook.