diff --git a/src/datepicker/datepicker.component.spec.ts b/src/datepicker/datepicker.component.spec.ts
new file mode 100644
index 0000000000..d529b98753
--- /dev/null
+++ b/src/datepicker/datepicker.component.spec.ts
@@ -0,0 +1,43 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { Component, ViewChild, OnInit } from '@angular/core';
+
+import { DatepickerModule, DatePickerComponent } from '.';
+
+@Component({
+ selector: 'test-cmp',
+ template: ``
+})
+class TestComponent implements OnInit {
+ @ViewChild(DatePickerComponent, { static: true }) datepicker: DatePickerComponent;
+
+ ngOnInit(): void {
+ this.datepicker.writeValue(new Date());
+ }
+}
+
+type TestFixture = ComponentFixture;
+
+describe('datepicker:', () => {
+ let fixture: TestFixture;
+
+ beforeEach(
+ async(() => TestBed.configureTestingModule({
+ declarations: [TestComponent],
+ imports: [
+ DatepickerModule.forRoot(),
+ BrowserAnimationsModule
+ ]
+ }).compileComponents())
+ );
+
+ it('should not throw undefined reference error when initializing value before content init hook',
+ () => {
+ // tslint:disable-next-line: no-floating-promises
+ expect(() => {
+ fixture = TestBed.createComponent(TestComponent);
+ fixture.detectChanges();
+ }).not.toThrowError(/^.*undefined.*$/gm);
+ }
+ );
+});
diff --git a/src/datepicker/datepicker.component.ts b/src/datepicker/datepicker.component.ts
index 5e87145d1c..41484ae69e 100644
--- a/src/datepicker/datepicker.component.ts
+++ b/src/datepicker/datepicker.component.ts
@@ -122,7 +122,7 @@ export class DatePickerComponent implements ControlValueAccessor {
undefined
);
- @ViewChild(DatePickerInnerComponent, { static: false })
+ @ViewChild(DatePickerInnerComponent, { static: true })
_datePicker: DatePickerInnerComponent;
/* tslint:disable-next-line: no-any*/