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
) {
}
}