ViewDestroyedError: Attempt to use a destroyed view: detectChanges

后端 未结 3 1439
离开以前
离开以前 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:31

    the reason that this issue is happening that you are deleting the reference on the sortableData or dragableData on the change event. in abstract class, the detectChange method is waiting for 250 ms before firing the change detect, at that time your view and component will be destroyed.

    setTimeout(() => {
            if (this.cdr !== null && this.cdr !== undefined &&
              !(this.cdr as ViewRef_).destroyed) {
              this.cdr.detectChanges();
            }
          }, 250);
    

提交回复
热议问题