Skip to content

Commit

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

Relates to angular#5035.
  • Loading branch information
crisbeto authored and andrewseguin committed Jul 28, 2017
1 parent ba000bd commit cf071c7
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 @@ -104,6 +107,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 @@ -120,7 +124,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 @@ -133,7 +142,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 cf071c7

Please sign in to comment.