Skip to content

Commit e405449

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 3bfe7f0 commit e405449

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', [
@@ -104,6 +107,7 @@ export class MdDialogContainer extends BasePortalHost {
104107
private _ngZone: NgZone,
105108
private _elementRef: ElementRef,
106109
private _focusTrapFactory: FocusTrapFactory,
110+
private _changeDetectorRef: ChangeDetectorRef,
107111
@Optional() @Inject(DOCUMENT) _document: any) {
108112

109113
super();
@@ -120,7 +124,12 @@ export class MdDialogContainer extends BasePortalHost {
120124
}
121125

122126
this._savePreviouslyFocusedElement();
123-
return this._portalHost.attachComponentPortal(portal);
127+
const componentRef = this._portalHost.attachComponentPortal(portal);
128+
129+
// Ensure that the initial view change are picked up.
130+
componentRef.changeDetectorRef.markForCheck();
131+
132+
return componentRef;
124133
}
125134

126135
/**
@@ -133,7 +142,12 @@ export class MdDialogContainer extends BasePortalHost {
133142
}
134143

135144
this._savePreviouslyFocusedElement();
136-
return this._portalHost.attachTemplatePortal(portal);
145+
const locals = this._portalHost.attachTemplatePortal(portal);
146+
147+
// Ensure that the initial view change are picked up.
148+
this._changeDetectorRef.markForCheck();
149+
150+
return locals;
137151
}
138152

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

0 commit comments

Comments
 (0)