injectRef
Generic types: | T |
Inject a proxy of the target dependency, which defers the actual injection until any of its properties is accessed.
Notes
This allows circular dependency injection (even though you ought not to), as long as the two classes do not access each other's properties during construction.
Presentation
function injectRef (
token: ProviderToken <T>,
injector: Injector = inject (Injector ),
): T;
Returns
T
Parameters
Name | Type | Description |
---|---|---|
token |
| |
injector |
|
Example usage
export class MyService {
private dep = injectRef (AnotherService);
}
export class AnotherService {
private dep = injectRef (MyService);
}