Skip to content

Commit d1128fe

Browse files
crisbetokara
authored andcommitted
fix(dialog): provide default value for MD_DIALOG_DATA token (#4120)
Fixes #4086.
1 parent 29caaf3 commit d1128fe

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/lib/dialog/dialog-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class MdDialogConfig {
4040
position?: DialogPosition;
4141

4242
/** Data being injected into the child component. */
43-
data?: any;
43+
data?: any = null;
4444

4545
// TODO(jelbourn): add configuration for lifecycle hooks, ARIA labelling.
4646
}

src/lib/dialog/dialog-injector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class DialogInjector implements Injector {
1515
return this._dialogRef;
1616
}
1717

18-
if (token === MD_DIALOG_DATA && this._data) {
18+
if (token === MD_DIALOG_DATA) {
1919
return this._data;
2020
}
2121

src/lib/dialog/dialog.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,11 @@ describe('MdDialog', () => {
349349
expect(instance.data.dateParam).toBe(config.data.dateParam);
350350
});
351351

352-
it('should throw if injected data is expected but none is passed', () => {
353-
expect(() => {
354-
dialog.open(DialogWithInjectedData);
355-
}).toThrow();
352+
it('should default to null if no data is passed', () => {
353+
let dialogRef: MdDialogRef<DialogWithInjectedData>;
354+
355+
expect(() => dialogRef = dialog.open(DialogWithInjectedData)).not.toThrow();
356+
expect(dialogRef.componentInstance.data).toBeNull();
356357
});
357358
});
358359

0 commit comments

Comments
 (0)