Skip to content

Commit

Permalink
fix(dialog): provide default value for MD_DIALOG_DATA token (#4120)
Browse files Browse the repository at this point in the history
Fixes #4086.
  • Loading branch information
crisbeto authored and kara committed Apr 21, 2017
1 parent 29caaf3 commit d1128fe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/dialog/dialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
2 changes: 1 addition & 1 deletion src/lib/dialog/dialog-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 5 additions & 4 deletions src/lib/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down

0 comments on commit d1128fe

Please sign in to comment.