mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(dialog): provide default value for MD_DIALOG_DATA token (#4120)
Fixes #4086.
This commit is contained in:
committed by
Kara
parent
29caaf3ea0
commit
d1128febe6
@@ -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.
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user