Skip to content

Commit da730df

Browse files
committed
chore(dialog): switch to OnPush change detection
Switches the dialog container to `OnPush` change detection. Relates to #5035.
1 parent f73cc97 commit da730df

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
@@ -17,6 +17,8 @@ import {
1717
EventEmitter,
1818
Inject,
1919
Optional,
20+
ChangeDetectionStrategy,
21+
ChangeDetectorRef,
2022
} from '@angular/core';
2123
import {
2224
animate,
@@ -50,6 +52,7 @@ export function throwMdDialogContentAlreadyAttachedError() {
5052
selector: 'md-dialog-container, mat-dialog-container',
5153
templateUrl: 'dialog-container.html',
5254
styleUrls: ['dialog.css'],
55+
changeDetection: ChangeDetectionStrategy.OnPush,
5356
encapsulation: ViewEncapsulation.None,
5457
animations: [
5558
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)