ViewDestroyedError: Attempt to use a destroyed view: detectChanges

后端 未结 3 1436
离开以前
离开以前 2021-01-03 18:49

I have the following component that creates an MdDialog

export class SideNavsComponent implements OnInit, AfterViewInit, OnDestroy {
  eventDispatcher: Event         


        
3条回答
  •  长发绾君心
    2021-01-03 19:28

    Padegal Saigiriraj is right. But instead of ViewRef_ use ViewRef. In short:

    setTimeout(() => {
      if (this.cdr && !(this.cdr as ViewRef).destroyed) {
        this.cdr.detectChanges();
      }
    });
    

    ViewRef stands for Angular view, specifically the host view as Angular site describes.

提交回复
热议问题