Angular как устранить ошибку "Circular dep for" - PullRequest
0 голосов
/ 01 мая 2020

Я делаю библиотеку angular с 3 компонентами:

  • FrameComponent (not publi c)
  • ApplicationComponent
  • SectionComponent

ApplicationComponent расширяет FrameComponent.

SectionComponent должен также расширять FrameComponent, НО ApplicationComponent содержит x sectionComponent (s).

Так что, если SectionComponent расширяет FrameComponent, я получаю эту ошибку:

ERROR Error: "Circular dep for SectionComponent"
    Angular 10
    SectionComponent_Factory section.component.ts:14
    Angular 5
    AppComponent_Template app.component.html:2
    Angular 20
    Angular 17

Причина точности, потому что в SectionComponent у меня есть поставщик для получения родительских атрибутов.

@Component({
  selector: 'ui-section',
  templateUrl: './section.component.html',
  styleUrls: ['./section.component.scss'],
  providers:  [ provideParent( SectionComponent ) ]
})

export class SectionComponent extends FrameComponent implements OnInit, AfterViewInit {
  ...
  constructor( elRef: ElementRef, @Optional() public parent: Parent){

  }

}

, если я комментирую /*@Optional() public parent: Parent*/ Ошибка исчезла.

Как я могу расширить SectionComponent FrameComponent без циклической ошибки dep?

1 Ответ

0 голосов
/ 06 мая 2020

Решение @SkipSelf() для SectionComponent

export class SectionComponent extends FrameComponent implements OnInit, AfterViewInit {
    ...
    constructor( elRef: ElementRef, @SkipSelf() @Optional() public parent?: FrameComponent ) {

    }
}
...