Angular material datepicker giving error: Cannot read property ‘subscribe’ of undefined

I am using Angular Material Datepicker. I have imported MatDatepickerModule in app.module.ts. However I am getting error.
My hmtl code:

<mat-form-field appearance="fill">
 <mat-label>Choose a date</mat-label>
 <input matInput [matDatepicker]="picker">
 <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
 <mat-datepicker #picker></mat-datepicker>

I getting this error:

ERROR TypeError: Cannot read property 'subscribe' of undefined
at new MatDatepickerInput (datepicker.js:3841)
at NodeInjectorFactory.MatDatepickerInput_Factory [as factory] (datepicker.js:4102)
at getNodeInjectable (core.js:5598)
at searchTokensOnInjector (core.js:5513)
at getOrCreateInjectable (core.js:5417)
at ɵɵdirectiveInject (core.js:20759)
at ɵɵinject (core.js:915)
at factory (core.js:16921)
at multiResolve (core.js:26736)
at NodeInjectorFactory.multiProvidersFactoryResolver [as factory] (core.js:26687)

Please help me with the solution.

Source: Angular Questions