Skip to content

Commit 2e41711

Browse files
committed
chore(dialog): add generic param for config data
Adds a generic parameter to the `MatDialogConfig` that indicates the type of its `data`. Fixes #4398.
1 parent 3c6f7a2 commit 2e41711

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/demo-app/dialog/dialog-demo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component, Inject, ViewChild, TemplateRef} from '@angular/core';
22
import {DOCUMENT} from '@angular/platform-browser';
3-
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
3+
import {MatDialog, MatDialogRef, MatDialogConfig, MAT_DIALOG_DATA} from '@angular/material';
44

55

66
@Component({
@@ -14,7 +14,7 @@ export class DialogDemo {
1414
lastAfterClosedResult: string;
1515
lastBeforeCloseResult: string;
1616
actionsAlignment: string;
17-
config = {
17+
config: MatDialogConfig = {
1818
disableClose: false,
1919
panelClass: 'custom-overlay-pane-class',
2020
hasBackdrop: true,

src/lib/dialog/dialog-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface DialogPosition {
2323
/**
2424
* Configuration for opening a modal dialog with the MatDialog service.
2525
*/
26-
export class MatDialogConfig {
26+
export class MatDialogConfig<D = any> {
2727

2828
/**
2929
* Where the attached component should live in Angular's *logical* component tree.
@@ -61,7 +61,7 @@ export class MatDialogConfig {
6161
position?: DialogPosition;
6262

6363
/** Data being injected into the child component. */
64-
data?: any = null;
64+
data?: D | null = null;
6565

6666
/** Layout direction for the dialog's content. */
6767
direction?: Direction = 'ltr';

src/lib/dialog/dialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export class MatDialog {
114114
* @param config Extra configuration options.
115115
* @returns Reference to the newly-opened dialog.
116116
*/
117-
open<T>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
118-
config?: MatDialogConfig): MatDialogRef<T> {
117+
open<T, D = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
118+
config?: MatDialogConfig<D>): MatDialogRef<T> {
119119

120120
const inProgressDialog = this.openDialogs.find(dialog => dialog._isAnimating());
121121

0 commit comments

Comments
 (0)