datepicker:(更改)事件或(selectedChanged)在mat-datepicker中不起作用

时间:2019-03-10 15:02:29

标签: datepicker angular6 angular-material-6

我正在处理的场景是->在选择日期选择器上的日期时,我要进行http调用,以执行一些计算 尝试使用(selectedChanged)进行此操作,但似乎不起作用,希望获得有关如何解决此问题的帮助,在此先感谢 以下是我正在尝试执行的HTML代码

    <div class="form-group m-form__group row">
    <div class="col-lg-4 m-form__group-sub">
    <mat-form-field class="example-full-width" appearance="outline">
    <mat-label>Policy Start Date</mat-label>
    <input matInput [min]="minDate" [max]="maxDate
    [matDatepicker]="picker4"
    placeholder="Choose a date" formControlName="policy_start_date" >
    <mat-datepicker-toggle matSuffix [for]="picker4" >
    </mat-datepicker-toggle>
  <mat-datepicker #picker4 (selectedChanged)="currentPeriodClicked()">
</mat-datepicker>
                                                </mat-form-field>
                                            </div>

1 个答案:

答案 0 :(得分:0)

MatDatepicker没有selectedChanged事件。尝试在MatDatepickerInput上使用dateChangedateInput事件:

<mat-form-field class="example-full-width" appearance="outline">

    <mat-label>Policy Start Date</mat-label>

    <input matInput [min]="minDate" [max]="maxDate 
        [matDatepicker]="picker4"
        (dateChange)="currentPeriodClicked()" 
        placeholder="Choose a date" 
        formControlName="policy_start_date" >

    <mat-datepicker-toggle matSuffix [for]="picker4" ></mat-datepicker-toggle>

    <mat-datepicker #picker4></mat-datepicker>

</mat-form-field>

请参阅:https://v6.material.angular.io/components/datepicker/overview#input-and-change-events