I am using @angular/material2 module to add datepicker to my angular 4 app.
here is my HTML
<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="Choose a date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
app.module.ts
import {MatDatepickerModule,MatNativeDateModule,MatFormFieldModule,MatInputModule} from '@angular/material';
when I click on the datepicker toggler the datepicker popup is opened at the very end of the page completely outside the form field it should be opened at.
any help will be appreciated.
The problem is that the DOM template of the Component is not ready when you call the datepicker in the Component and so jquery can't bind the events to the DOM element. Try to use a timeout in your component. Note ` is missing before and after the template text.
A datepicker is composed of a text input and a calendar pop-up, connected via the matDatepicker property on the text input. There is also an optional datepicker toggle button that gives the user an easy way to open the datepicker pop-up.
My problem was I had set .mat-form-field-underline
to hidden. The date picker uses this element to determine position.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With