Set default value for angular material datePicker with angular 5

前端 未结 8 581
独厮守ぢ
独厮守ぢ 2021-01-11 13:14

I\'m using a date picker from angular material. I want to set a default value but it is not showing the value.



        
相关标签:
8条回答
  • 2021-01-11 13:53

    In a group of form controllers, you can use the default date as seen in follows.

     birthdayCtrl: ['1999-01-31']
    
    0 讨论(0)
  • 2021-01-11 13:53

    Using Template driven approach the solution is as followed.

     selectedDate = new Date();
    
    <input class="form-control"
                         matInput
                         [matDatepicker]="dp3"
                         [min]="today"
                         [max]="max"
                         disabled
                         [(ngModel)]="selectedDate"
                         (ngModelChange)="dateUpdated()"
                         name="currentDate"
                       />
                       <mat-datepicker-toggle
                         matSuffix
                         [for]="dp3"
                       ></mat-datepicker-toggle>
                       <mat-datepicker #dp3 disabled="false"></mat-datepicker> ```
    
    0 讨论(0)
提交回复
热议问题