Ember.inject

Ember.inject Namespace

PUBLIC

Defined in: packages/ember-runtime/lib/inject.js:6

Module: ember-runtime

Namespace for injection helper methods.

controller (name) Ember.InjectedPropertypublic

Defined in packages/ember-runtime/lib/controllers/controller.js:31
Available since 1.10.0

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

Example:

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:

App.PostController = Ember.Controller.extend({
  needs: 'posts',
  posts: Ember.computed.alias('controllers.posts')
});

Parameters:

name String
(optional) name of the controller to inject, defaults to the property's name

Returns:

Ember.InjectedProperty
injection descriptor instance

service (name) Ember.InjectedPropertypublic

Defined in packages/ember-runtime/lib/system/service.js:5
Available since 1.10.0

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:

App.ApplicationRoute = Ember.Route.extend({
  authManager: Ember.inject.service('auth'),

  model: function() {
    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.

Parameters:

name String
(optional) name of the service to inject, defaults to the property's name

Returns:

Ember.InjectedProperty
injection descriptor instance

© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/classes/Ember.inject.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部