Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use date picker in Angular 2?

I have tried many date picker in my angular2 app but none of them is working.Although the date picker is displaying on the view but the value of selected date is not getting in the ngModel variable.

like image 661
Mubashir Avatar asked Jan 14 '16 11:01

Mubashir


People also ask

How do you use a mat Datepicker?

mat-datepicker exampleAdd a template reference variable mat-datepicker element. Connect mat-datepicker to input element via [matDatepicker] property. Finally add date picker toggle button to display or hide calender popup by using mat-datepicker-toggle element.

How do I use Datepicker in angular 6?

Adding Angular 6 DatePickerImport the DatePicker module into the Angular application (app. module. ts) from the ej2-angular-calendars package. Define the Angular DatePicker code within the app.

How can I get mat Datepicker value?

To use Datepicker in our application, we need to import MatDatepickerModule in application module. On this page we will create Datepicker and fetch selected value using NgModel , FormControl and FormGroup .


1 Answers

In fact, you can use a datepicker by simply adding the date value into the type attribute of your inputs:

<input type="date" [(ngModel)]="company.birthdate"/> 

In some browsers like Chrome and Microsoft Edge (not in Firefox), you can click on the icon within the input to display the date picker. Icons appear only when you mouse is over the input.

To have something cross browsers, you should consider to use Angular2 compliant libraries like:

  • https://github.com/kekeh/mydatepicker
  • https://github.com/jkuri/ng2-datepicker
like image 117
Thierry Templier Avatar answered Sep 22 '22 19:09

Thierry Templier