Skip to content

Commit

Permalink
chore(dialog): switch to OnPush change detection
Browse files Browse the repository at this point in the history
Switches the dialog container to `OnPush` change detection.

Relates to #5035.
  • Loading branch information
crisbeto authored and andrewseguin committed Jul 24, 2017
1 parent 374aaff commit 7e54670
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/lib/dialog/dialog-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
EventEmitter,
Inject,
Optional,
ChangeDetectionStrategy,
ChangeDetectorRef,
} from '@angular/core';
import {
animate,
Expand Down Expand Up @@ -49,6 +51,7 @@ export function throwMdDialogContentAlreadyAttachedError() {
selector: 'md-dialog-container, mat-dialog-container',
templateUrl: 'dialog-container.html',
styleUrls: ['dialog.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
animations: [
trigger('slideDialog', [
Expand Down Expand Up @@ -100,6 +103,7 @@ export class MdDialogContainer extends BasePortalHost {
private _ngZone: NgZone,
private _elementRef: ElementRef,
private _focusTrapFactory: FocusTrapFactory,
private _changeDetectorRef: ChangeDetectorRef,
@Optional() @Inject(DOCUMENT) _document: any) {

super();
Expand All @@ -116,7 +120,12 @@ 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;
}

/**
Expand All @@ -129,7 +138,12 @@ export class MdDialogContainer extends BasePortalHost {
}

this._savePreviouslyFocusedElement();
return this._portalHost.attachTemplatePortal(portal);
const locals = this._portalHost.attachTemplatePortal(portal);

// Ensure that the initial view change are picked up.
this._changeDetectorRef.markForCheck();

return locals;
}

/** Moves the focus inside the focus trap. */
Expand Down

0 comments on commit 7e54670

Please sign in to comment.