Skip to content

Commit 7e54670

Browse files
crisbetoandrewseguin
authored andcommitted
chore(dialog): switch to OnPush change detection
Switches the dialog container to `OnPush` change detection. Relates to #5035.
1 parent 374aaff commit 7e54670

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/lib/dialog/dialog-container.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
EventEmitter,
1717
Inject,
1818
Optional,
19+
ChangeDetectionStrategy,
20+
ChangeDetectorRef,
1921
} from '@angular/core';
2022
import {
2123
animate,
@@ -49,6 +51,7 @@ export function throwMdDialogContentAlreadyAttachedError() {
4951
selector: 'md-dialog-container, mat-dialog-container',
5052
templateUrl: 'dialog-container.html',
5153
styleUrls: ['dialog.css'],
54+
changeDetection: ChangeDetectionStrategy.OnPush,
5255
encapsulation: ViewEncapsulation.None,
5356
animations: [
5457
trigger('slideDialog', [
@@ -100,6 +103,7 @@ export class MdDialogContainer extends BasePortalHost {
100103
private _ngZone: NgZone,
101104
private _elementRef: ElementRef,
102105
private _focusTrapFactory: FocusTrapFactory,
106+
private _changeDetectorRef: ChangeDetectorRef,
103107
@Optional() @Inject(DOCUMENT) _document: any) {
104108

105109
super();
@@ -116,7 +120,12 @@ export class MdDialogContainer extends BasePortalHost {
116120
}
117121

118122
this._savePreviouslyFocusedElement();
119-
return this._portalHost.attachComponentPortal(portal);
123+
const componentRef = this._portalHost.attachComponentPortal(portal);
124+
125+
// Ensure that the initial view change are picked up.
126+
componentRef.changeDetectorRef.markForCheck();
127+
128+
return componentRef;
120129
}
121130

122131
/**
@@ -129,7 +138,12 @@ export class MdDialogContainer extends BasePortalHost {
129138
}
130139

131140
this._savePreviouslyFocusedElement();
132-
return this._portalHost.attachTemplatePortal(portal);
141+
const locals = this._portalHost.attachTemplatePortal(portal);
142+
143+
// Ensure that the initial view change are picked up.
144+
this._changeDetectorRef.markForCheck();
145+
146+
return locals;
133147
}
134148

135149
/** Moves the focus inside the focus trap. */

0 commit comments

Comments
 (0)