@service
Injects a service singleton into a class property.
Syntax
@service name; | @service('full-name') alias; Returns
PropertyDecorator — A decorator that lazily resolves the service.
Examples
import Component from '@glimmer/component';
import { service } from '@ember/service';
export default class ProfileComponent extends Component {
@service session;
@service('shopping-cart') cart;
get name() {
return this.session.currentUser?.name;
}
}
Notes
Import from @ember/service (the modern path). With no argument the
property name is the service name; pass a string to alias a differently
named service. Injection is lazy, so unused services are never created.