I'm using the new version of angular and angular material. I need to get the value of the datepicker
at the moment the user change the date to then pass that value to a function and do something.
datepicker
<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="Choose a date" [(ngModel)]="roomsFilter.date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker [(ngModel)]="roomsFilter.date" ngDefaultControl (selectedChanged)="onChange($event)"></mat-datepicker>
</mat-form-field>
and this the function.
public onChange(event: any, newDate: any): void {
console.log(event.target.value);
// this.getData(newDate);
}
According to the official documentation, the MatDatepickerInput has a dateInput EventEmitter and it's emits the selected date.
Please check this demo link So you will get more idea. Example
Sorry i didn´t post the answer before, but i solved the problem with the comment of @AJT_82. here is the code.
Component HTML
compoment ts
Basically i just past the
$event
of thedatepicker
to get the value.