diff --git a/src/lib/dialog/dialog-config.ts b/src/lib/dialog/dialog-config.ts index 96b4586e73d5..f8f1b648a3e3 100644 --- a/src/lib/dialog/dialog-config.ts +++ b/src/lib/dialog/dialog-config.ts @@ -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. } diff --git a/src/lib/dialog/dialog-injector.ts b/src/lib/dialog/dialog-injector.ts index 87f0d7ffdc91..c6edc4e1b471 100644 --- a/src/lib/dialog/dialog-injector.ts +++ b/src/lib/dialog/dialog-injector.ts @@ -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; } diff --git a/src/lib/dialog/dialog.spec.ts b/src/lib/dialog/dialog.spec.ts index 187c37908e46..af50e26c4ae8 100644 --- a/src/lib/dialog/dialog.spec.ts +++ b/src/lib/dialog/dialog.spec.ts @@ -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; + + expect(() => dialogRef = dialog.open(DialogWithInjectedData)).not.toThrow(); + expect(dialogRef.componentInstance.data).toBeNull(); }); });