Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
8.9k views
in Technique[技术] by (71.8m points)

NG0200: Circular dependency in DI detected,为什么并且我该怎么做?

我想往子组件中注入父组件,但是有一个错误:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...