Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datepicker: (change) event or (selectedChanged) does not work in mat-datepicker

The scenario i am working on is -> on selection of the date on mat datepicker i want to make a http call which performs a few calculations Trying to do this using (selectedChanged), but doesn't seem working, wanted help on how i could fix this, thanks in advance The below is the HTML code where i am trying to do this

    <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>
like image 765
anglrlearner Avatar asked Nov 23 '25 12:11

anglrlearner


1 Answers

MatDatepicker does not have a selectedChanged event. Try using either the dateChange or dateInput event on MatDatepickerInput instead:

<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>

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

like image 115
G. Tranter Avatar answered Nov 25 '25 10:11

G. Tranter