Skip to content

Commit 0c9b0b3

Browse files
committed
chore(dialog): switch to OnPush change detection
Switches the dialog to OnPush change detection.
1 parent 85a6fff commit 0c9b0b3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/lib/dialog/dialog-container.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
ChangeDetectorRef,
1818
ViewChild,
1919
ViewEncapsulation,
20+
ChangeDetectionStrategy,
2021
} from '@angular/core';
2122
import {animate, AnimationEvent, state, style, transition, trigger} from '@angular/animations';
2223
import {DOCUMENT} from '@angular/platform-browser';
@@ -50,6 +51,7 @@ export function throwMdDialogContentAlreadyAttachedError() {
5051
templateUrl: 'dialog-container.html',
5152
styleUrls: ['dialog.css'],
5253
encapsulation: ViewEncapsulation.None,
54+
changeDetection: ChangeDetectionStrategy.OnPush,
5355
animations: [
5456
trigger('slideDialog', [
5557
// Note: The `enter` animation doesn't transition to something like `translate3d(0, 0, 0)
@@ -117,7 +119,13 @@ export class MdDialogContainer extends BasePortalHost {
117119
}
118120

119121
this._savePreviouslyFocusedElement();
120-
return this._portalHost.attachComponentPortal(portal);
122+
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;
121129
}
122130

123131
/**
@@ -130,7 +138,12 @@ export class MdDialogContainer extends BasePortalHost {
130138
}
131139

132140
this._savePreviouslyFocusedElement();
133-
return this._portalHost.attachTemplatePortal(portal);
141+
142+
const locals = this._portalHost.attachTemplatePortal(portal);
143+
144+
this._changeDetectorRef.markForCheck();
145+
146+
return locals;
134147
}
135148

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

0 commit comments

Comments
 (0)