fix(dialog): add generic parameter for the dialog result to open method (#11059)

This commit is contained in:
Kristiyan Kostadinov
2018-05-01 10:33:15 -04:00
committed by Joey Perrott
parent cfe6c1d40d
commit bf1bdc0a6d
+10 -7
View File
@@ -114,8 +114,8 @@ export class MatDialog {
* @param config Extra configuration options.
* @returns Reference to the newly-opened dialog.
*/
open<T, D = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
config?: MatDialogConfig<D>): MatDialogRef<T> {
open<T, D = any, R = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
config?: MatDialogConfig<D>): MatDialogRef<T, R> {
config = _applyConfigDefaults(config, this._defaultOptions || new MatDialogConfig());
@@ -125,8 +125,10 @@ export class MatDialog {
const overlayRef = this._createOverlay(config);
const dialogContainer = this._attachDialogContainer(overlayRef, config);
const dialogRef =
this._attachDialogContent<T>(componentOrTemplateRef, dialogContainer, overlayRef, config);
const dialogRef = this._attachDialogContent<T, R>(componentOrTemplateRef,
dialogContainer,
overlayRef,
config);
// If this is the first dialog that we're opening, hide all the non-overlay content.
if (!this.openDialogs.length) {
@@ -221,15 +223,16 @@ export class MatDialog {
* @param config The dialog configuration.
* @returns A promise resolving to the MatDialogRef that should be returned to the user.
*/
private _attachDialogContent<T>(
private _attachDialogContent<T, R>(
componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
dialogContainer: MatDialogContainer,
overlayRef: OverlayRef,
config: MatDialogConfig): MatDialogRef<T> {
config: MatDialogConfig): MatDialogRef<T, R> {
// Create a reference to the dialog we're creating in order to give the user a handle
// to modify and close it.
const dialogRef = new MatDialogRef<T>(overlayRef, dialogContainer, this._location, config.id);
const dialogRef =
new MatDialogRef<T, R>(overlayRef, dialogContainer, this._location, config.id);
// When the dialog backdrop is clicked, we want to close it.
if (config.hasBackdrop) {