NG0200: Circular dependency in DI detected,Why and How to do?

Discussão em 'Angular' iniciado por blunts, Setembro 13, 2024.

  1. blunts

    blunts Guest

    I want inject ParentCompoent to ChildComponent,

    But have a error is:

    Error: NG0200: Circular dependency in DI detected for ParentComponent

    parent Component:

    @Component({
    selector: 'cy-parent',
    templateUrl: './parent.component.html',
    styleUrls: ['./parent.component.scss'],
    providers: [
    {provide: ParentComponent, useExisting: forwardRef(() => ParentComponent)}
    ]
    })

    export class ParentComponent {
    constructor() { }
    }


    child component:

    @Component({
    selector: 'cy-child',
    templateUrl: './child.component.html',
    styleUrls: ['./child.component.scss'],

    })
    export class ChildComponent implements OnInit {
    constructor(
    @SkipSelf() @Optional() public _parentComp?: ParentComponent
    ) {

    }
    }

    Continue reading...

Compartilhe esta Página