Skip to content

Function: injection()

ts
function injection<T>(optionsOrInjectionId: 
  | InjectionOptions<T>
| ServiceIdentifier<T>): InjectionDecorator<T>;

Defined in: src/wirestate-lit/consumption/injection.ts:84

Injects a container value into a Lit element property.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
optionsOrInjectionId| InjectionOptions<T> | ServiceIdentifier<T>Service token or options.

Returns

InjectionDecorator<T>

Lit property decorator.

Remarks

The property follows the nearest container context unless once is true.

Examples

typescript
class MyElement extends LitElement {
  @injection(MyService)
  private myService!: MyService;

  public render() {
    return html`<div>${this.myService.getName()}</div>`;
  }
}
typescript
class MyElement extends LitElement {
  @injection({ injectionId: MyService, once: true })
  private myService!: MyService;

  public render() {
    return html`<div>${this.myService.getName()}</div>`;
  }
}