Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/lib/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down