fix(dialog): provide default value for MD_DIALOG_DATA token (#4120)

Fixes #4086.
This commit is contained in:
Kristiyan Kostadinov
2017-04-21 23:39:39 +02:00
committed by Kara
parent 29caaf3ea0
commit d1128febe6
3 changed files with 7 additions and 6 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ export class MdDialogConfig {
position?: DialogPosition;
/** Data being injected into the child component. */
data?: any;
data?: any = null;
// TODO(jelbourn): add configuration for lifecycle hooks, ARIA labelling.
}
+1 -1
View File
@@ -15,7 +15,7 @@ export class DialogInjector implements Injector {
return this._dialogRef;
}
if (token === MD_DIALOG_DATA && this._data) {
if (token === MD_DIALOG_DATA) {
return this._data;
}
+5 -4
View File
@@ -349,10 +349,11 @@ describe('MdDialog', () => {
expect(instance.data.dateParam).toBe(config.data.dateParam);
});
it('should throw if injected data is expected but none is passed', () => {
expect(() => {
dialog.open(DialogWithInjectedData);
}).toThrow();
it('should default to null if no data is passed', () => {
let dialogRef: MdDialogRef<DialogWithInjectedData>;
expect(() => dialogRef = dialog.open(DialogWithInjectedData)).not.toThrow();
expect(dialogRef.componentInstance.data).toBeNull();
});
});