Function
inject (name) Ember.InjectedProperty public
Module: | @ember/service |
---|
Defined in packages/ember-runtime/lib/system/service.js:9
Available since v1.10.0
import { inject } from '@ember/service';
- 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:
app/routes/application.js
import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; export default Route.extend({ authManager: 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.
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/2.18/functions/@ember%2Fservice/inject