diff --git a/src/lib/datepicker/datepicker.spec.ts b/src/lib/datepicker/datepicker.spec.ts index 3f87fc50749d..c9d0ff8768ee 100644 --- a/src/lib/datepicker/datepicker.spec.ts +++ b/src/lib/datepicker/datepicker.spec.ts @@ -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(); })); diff --git a/src/lib/datepicker/datepicker.ts b/src/lib/datepicker/datepicker.ts index cc25a957df13..cbd4c0da8cf7 100644 --- a/src/lib/datepicker/datepicker.ts +++ b/src/lib/datepicker/datepicker.ts @@ -147,7 +147,8 @@ export class MatDatepicker 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);