I have the following component that creates an MdDialog
export class SideNavsComponent implements OnInit, AfterViewInit, OnDestroy {
eventDispatcher: Event
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.
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);
The issue is the close action of the dialog is removing the item from the view, and your EventDispatcher IS NOT AN ANGULAR METHOD so it fires outside the zone context and freaks it out. It goes like this:
You can either use a different method to communicate with the dialog, or switch to onPush() for change detection
I suggest you Use the afterClosed
handle instead:
this. authEmailDialogRef.afterClosed().subscribe(result => {
console.log(`Dialog result: ${result}`); // Pizza!
});
I pulled that snippet straight from the docs: HERE