The old way of injecting dependencies using the constructor:
import { Component } from '@angular/core';
@Component({ / ... / })
export class MyComponent {
constructor(
@Inject(SOME_TOKEN) private readonly someToken: string,
private readonly myService: MyService,
private readonly httpClient: HttpClient,
) {}
}
The new way of injecting dependencies using the inject() function:
import { Component, inject } from '@angular/core';
@Component({ / ... / })
export class MyComponent {
private readonly someToken = inject(SOME_TOKEN);
private readonly myService = inject(MyService);
private readonly httpClient = inject(HttpClient);
}
Quelques explications concernant l'injection des dépendances avec Ivy dans Angular 9
another tuto about angular schematics