chore(dialog): switch to OnPush change detection (#5422)

Switches the dialog container to `OnPush` change detection.

Relates to #5035.
This commit is contained in:
Kristiyan Kostadinov
2017-07-28 18:06:32 +03:00
committed by Andrew Seguin
parent ba000bdeee
commit cf071c75f5
+16 -2
View File
@@ -16,6 +16,8 @@ import {
EventEmitter,
Inject,
Optional,
ChangeDetectionStrategy,
ChangeDetectorRef,
} from '@angular/core';
import {
animate,
@@ -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', [
@@ -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();
@@ -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;
}
/**
@@ -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. */