From 4a1f10ecd5eee00b3ecb7e08b93aa5dd03a32641 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 8 Aug 2017 22:25:19 +0200 Subject: [PATCH] fix(dialog): support passing in dialog result through all MdDialogClose selectors (#6293) Fixes not being able to pass in a dialog result through the `mdDialogClose`, `matDialogClose` and `mat-dialog-close` selectors, even though they are allowed by the `MdDialogClose` directive. Fixes #6278. --- src/lib/dialog/dialog-content-directives.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lib/dialog/dialog-content-directives.ts b/src/lib/dialog/dialog-content-directives.ts index 6f62aa5a4305..8ff30549f62a 100644 --- a/src/lib/dialog/dialog-content-directives.ts +++ b/src/lib/dialog/dialog-content-directives.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directive, Input, Optional, OnInit} from '@angular/core'; +import {Directive, Input, OnChanges, OnInit, Optional, SimpleChanges} from '@angular/core'; import {MdDialogRef} from './dialog-ref'; import {MdDialogContainer} from './dialog-container'; @@ -25,17 +25,27 @@ let dialogElementUid = 0; 'type': 'button', // Prevents accidental form submits. } }) -export class MdDialogClose { +export class MdDialogClose implements OnChanges { /** Screenreader label for the button. */ @Input('aria-label') ariaLabel: string = 'Close dialog'; /** Dialog close input. */ @Input('md-dialog-close') dialogResult: any; - /** Dialog close input for compatibility mode. */ - @Input('mat-dialog-close') set _matDialogClose(value: any) { this.dialogResult = value; } + @Input('matDialogClose') _matDialogClose: any; + @Input('mdDialogClose') _mdDialogClose: any; + @Input('mat-dialog-close') _matDialogCloseResult: any; constructor(public dialogRef: MdDialogRef) { } + + ngOnChanges(changes: SimpleChanges) { + const proxiedChange = changes._matDialogClose || changes._mdDialogClose || + changes._matDialogCloseResult; + + if (proxiedChange) { + this.dialogResult = proxiedChange.currentValue; + } + } } /**