From 0c9b0b39ed48b106ef74adc3d08747bd1ce1d15d Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sat, 5 Aug 2017 09:42:30 +0200 Subject: [PATCH] chore(dialog): switch to OnPush change detection Switches the dialog to OnPush change detection. --- src/lib/dialog/dialog-container.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/dialog/dialog-container.ts b/src/lib/dialog/dialog-container.ts index 816b4ce11ea8..bb9c0e0127dd 100644 --- a/src/lib/dialog/dialog-container.ts +++ b/src/lib/dialog/dialog-container.ts @@ -17,6 +17,7 @@ import { ChangeDetectorRef, ViewChild, ViewEncapsulation, + ChangeDetectionStrategy, } from '@angular/core'; import {animate, AnimationEvent, state, style, transition, trigger} from '@angular/animations'; import {DOCUMENT} from '@angular/platform-browser'; @@ -50,6 +51,7 @@ export function throwMdDialogContentAlreadyAttachedError() { templateUrl: 'dialog-container.html', styleUrls: ['dialog.css'], encapsulation: ViewEncapsulation.None, + changeDetection: ChangeDetectionStrategy.OnPush, animations: [ trigger('slideDialog', [ // Note: The `enter` animation doesn't transition to something like `translate3d(0, 0, 0) @@ -117,7 +119,13 @@ export class MdDialogContainer extends BasePortalHost { } this._savePreviouslyFocusedElement(); - return this._portalHost.attachComponentPortal(portal); + + const componentRef = this._portalHost.attachComponentPortal(portal); + + // Ensure that the initial view change are picked up. + componentRef.changeDetectorRef.markForCheck(); + + return componentRef; } /** @@ -130,7 +138,12 @@ export class MdDialogContainer extends BasePortalHost { } this._savePreviouslyFocusedElement(); - return this._portalHost.attachTemplatePortal(portal); + + const locals = this._portalHost.attachTemplatePortal(portal); + + this._changeDetectorRef.markForCheck(); + + return locals; } /** Moves the focus inside the focus trap. */