Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 7dbcadd

Browse files
authored
feat(dialog): Add generic parameter for dialog result (#2074)
Adds the `R` generic parameter to MdcDialog open method; allows for the dialog result to be strongly typed.
1 parent 8e5f85b commit 7dbcadd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/dialog/dialog.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class MdcDialog implements OnDestroy {
7575
* @param config Extra configuration options.
7676
* @returns Reference to the newly-opened dialog.
7777
*/
78-
open<T, D = any, R = {}>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
78+
open<T, D = any, R = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
7979
config?: MdcDialogConfig<D>): MdcDialogRef<T, R> {
8080

8181
config = _applyConfigDefaults(config, this._defaultOptions || new MdcDialogConfig());
@@ -86,7 +86,7 @@ export class MdcDialog implements OnDestroy {
8686

8787
const overlayRef = this._createOverlay();
8888
const dialogContainer = this._attachDialogContainer(overlayRef, config);
89-
const dialogRef = this._attachDialogContent<T>(componentOrTemplateRef,
89+
const dialogRef = this._attachDialogContent<T, R>(componentOrTemplateRef,
9090
dialogContainer,
9191
overlayRef,
9292
config);
@@ -154,15 +154,15 @@ export class MdcDialog implements OnDestroy {
154154
* @param config The dialog configuration.
155155
* @returns A promise resolving to the MdcDialogRef that should be returned to the user.
156156
*/
157-
private _attachDialogContent<T>(
157+
private _attachDialogContent<T, R>(
158158
componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
159159
dialogContainer: MdcDialogPortal,
160160
overlayRef: OverlayRef,
161-
config: MdcDialogConfig): MdcDialogRef<T> {
161+
config: MdcDialogConfig): MdcDialogRef<T, R> {
162162

163163
// Create a reference to the dialog we're creating in order to give the user a handle
164164
// to modify and close it.
165-
const dialogRef = new MdcDialogRef<T>(overlayRef, dialogContainer, config.id);
165+
const dialogRef = new MdcDialogRef<T, R>(overlayRef, dialogContainer, config.id);
166166

167167
if (componentOrTemplateRef instanceof TemplateRef) {
168168
dialogContainer.attachTemplatePortal(
@@ -171,7 +171,7 @@ export class MdcDialog implements OnDestroy {
171171
} else {
172172
const injector = this._createInjector<T>(config, dialogRef, dialogContainer);
173173
const contentRef = dialogContainer.attachComponentPortal<T>(
174-
new ComponentPortal(componentOrTemplateRef, undefined, injector));
174+
new ComponentPortal(componentOrTemplateRef, config.viewContainerRef, injector));
175175
dialogRef.componentInstance = contentRef.instance;
176176
}
177177

0 commit comments

Comments
 (0)