fix(datepicker): make sure _datepickerInput exists before accessing its (#7033)

* fix(datepicker): make sure _datepickerInput exists before accessing its
disabled property.

* add test
This commit is contained in:
mmalerba
2017-09-29 13:14:42 -07:00
committed by Andrew Seguin
parent 2dcb76c8f9
commit 2129b7a7f9
2 changed files with 6 additions and 1 deletions
+4
View File
@@ -304,6 +304,10 @@ describe('MatDatepicker', () => {
fixture.detectChanges();
}));
it('should not throw when accessing disabled property', () => {
expect(() => testComponent.datepicker.disabled).not.toThrow();
});
it('should throw when opened with no registered inputs', async(() => {
expect(() => testComponent.datepicker.open()).toThrow();
}));
+2 -1
View File
@@ -147,7 +147,8 @@ export class MatDatepicker<D> implements OnDestroy {
/** Whether the datepicker pop-up should be disabled. */
@Input()
get disabled() {
return this._disabled === undefined ? this._datepickerInput.disabled : this._disabled;
return this._disabled === undefined && this._datepickerInput ?
this._datepickerInput.disabled : this._disabled;
}
set disabled(value: any) {
const newValue = coerceBooleanProperty(value);