Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@angular/material datepicker position

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.

like image 883
Peter Wilson Avatar asked Oct 14 '17 16:10

Peter Wilson


People also ask

Why datepicker is not working in angular?

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.

What is Mat-datepicker-toggle?

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.


1 Answers

My problem was I had set .mat-form-field-underline to hidden. The date picker uses this element to determine position.

like image 170
Mikel Porras Hoogland Avatar answered Sep 30 '22 19:09

Mikel Porras Hoogland