Skip to content

Self referencing component doesn't work in Angular 8 #15429

@deftomat

Description

@deftomat

We just upgrade from v7 to v8.2.3 and now we have the following error:

Can't resolve all parameters for SectionComponent: (?).

Component's code:

@Component({
  selector: 'section',
  template: '<ng-content></ng-content>'
})
export class SectionComponent {
  constructor(
    @SkipSelf()
    @Optional()
    private parent: SectionComponent | null
  ) {}

  get level(): number {
    return this.parent ? this.parent.level + 1 : 1;
  }
}

It worked flawlessly in v7. We are using this component across the whole app as a multiple components depends on level to know how they should render itself.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions