我想往子组件中注入父组件,但是有一个错误:
Error: NG0200: Circular dependency in DI detected for ParentComponent
子组件:
@Component({
selector: 'cy-parent',
templateUrl: './parent.component.html',
styleUrls: ['./parent.component.scss'],
providers: [
{provide: ParentComponent, useExisting: forwardRef(() => ParentComponent)}
]
})
export class ParentComponent {
constructor() { }
}
父组件:
@Component({
selector: 'cy-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.scss'],
})
export class ChildComponent implements OnInit {
constructor(
@SkipSelf() @Optional() public _parentComp?: ParentComponent
) {
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…