2

Is it possible to somehow catch click event on angular material datepicker toggle icon? I want trigger function foo().

My implementation looks like:

          <mat-form-field class="example-full-width">
            <input matInput [matDatepicker]="picker" placeholder="Date">
            <mat-datepicker-toggle matSuffix [for]="picker" (click)="foo()"></mat-datepicker-toggle>
            <mat-datepicker #picker></mat-datepicker>
          </mat-form-field>

I have already tried put (click)="foo()" to mat-datepicker-toggle and mat-datepicker element but event not triggered.

2 Answers 2

6

Use opened and closed event emitter provided by angular date picker component to listen open and close of calander component.

<mat-form-field class="example-full-width">
            <input  matInput [matDatepicker]="picker" placeholder="Date">
            <mat-datepicker-toggle            
             matSuffix [for]="picker" (click)="foo()"></mat-datepicker-toggle>
            <mat-datepicker 
            #ref
            (opened)="toggle(ref)"
            (closed)="toggle(ref)"
            #picker></mat-datepicker>
</mat-form-field>

Example

Sign up to request clarification or add additional context in comments.

1 Comment

you save my day
0

Try to (focus)="foo()" instead of (click)="foo()"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.