I have a set of different child views which I require to be loaded on a condition. Everything works fine however, I receive a message that ViewDestroyedError: Attempt to use a destroyed view: detectChanges. So I believe that this is causing that on parent load, all the views are rendered once. However, whenever the condition satisfy for the view, it might be possible that it was already rendered before hence saying that attempting to use a destroyed view.


<div class="parent>
    <app-dropdown *ngSwitchCase="'dropdown'" [reply]="answer" (response)="myResponse($event)"></app-dropdown>
    <app-select *ngSwitchCase="'select'" [reply]="answer" (response)="myResponse($event)"></app-select>
    <app-input *ngSwitchCase="'input'" [reply]="answer" (response)="myResponse($event)"></app-input>


我尝试添加ChangeDetectorRef,但是它对我来说是新的,因此无法找到方法。 我的孩子之一的代码如下。

export class DropdownComponent implements OnInit {
  @Input() reply: any;
  @Output() response = new EventEmitter();
  constructor(private cdRef: ChangeDetectorRef) {

  ngOnInit() {
    if (this.reply.answerType === 'speciality') {

  ngOnDestroy(): void {


I'm just checking the reply and if it's as per condition, then emitting the response. But getting blank response as the view is already rendered with other component. I tried changing ngOnChange() also instead of ngOnInit but still same issue.