Search code examples
angularangular-ivyangular9

Angular 8 to 9, unable to import the service into the class that use inheritance


Upgraded Angular from v8 to v9. The project use its "unique" way of defining things (instead of composition), for example classes that extend base classes along with the services.

For example:

export class TimeSeriesFormStrategy extends FormStrategyDruidBase {
  constructor(
    protected dashboardService: DashboardService,
    protected i18nService: I18NService,
    protected filterSelectService: FilterSelectService,
    protected formBuilder: FormBuilder
  ) {
    super(DashboardWidget.TypeEnum.TimeLines, dashboardService, i18nService, filterSelectService, formBuilder);

    this.basicSteps = [

After migrating to Angular 9, getting:

enter image description here

Getting the same type of error for other similar classes.

The root of the problem seems to be related to trying to inject services into clesses which use inheritance. Unfortunately, at this level - it is not possible to throw this away without big refactor.

Any way to handle the error?


Solution

  • The short answer is:

    • All classes that are services or used as servies should be annotated with the @Injectable() decorator.

    Details answer is here: https://github.com/angular/angular/issues/19417#issuecomment-332851205.

    Seems like the requirement mas optional in Angular 8, but became mandatory in Angular 9.