Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set value angular material datepicker, from input outside

I want to set value of angular material datepicker, but from input outside material datepicker input

Please see this for more information: angular-material-datepicker

<mat-form-field>
    <input matInput placeholder="set date picker on blur 
    (blur)="setDatepicker()">
</mat-form-field> <br>
<mat-form-field class="example-full-width">
    <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>
like image 710
Jiraiyaa Avatar asked Sep 23 '26 20:09

Jiraiyaa


1 Answers

You need update

HTML

(blur)="setDatepicker($event.target.value)">

<input matInput [(ngModel)]="input" [matDatepicker]="picker" placeholder="Choose a date">

TS

export class DatepickerFilterExample {
  input: any;
  setDatepicker(val) {
    //alert(val)
    this.input = new Date(val);
  }
}

Forked https://stackblitz.com/edit/angular-material-datepicker-example-2

like image 58
Hien Nguyen Avatar answered Sep 25 '26 10:09

Hien Nguyen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!