I am using angular material datepicker directive and I have few problems.
1. When I open date picker dialog and select any date, date shows up in input text box, but I want to call a function when ever any change occur in input text box.
Right now if I manually enter any value in input text box, I am triggering function using (input) directive and it is working fine as shown in code. I want to trigger same function when date gets change using date picker dialog.
2. I also want to change the format of date from mm/dd/yyyy to dd/mm/yyyy when selected from date picker dialog. Here mm/dd/yyyy is set by default in this directive.
<input matInput [matDatepicker]="organizationValue" formControlName="organizationValue" (input)="orgValueChange(i)">
<mat-datepicker-toggle matSuffix [for]="organizationValue"></mat-datepicker-toggle>
<mat-datepicker #organizationValue></mat-datepicker>
In your html you can use (ngModelChange)="functionName()" to trigger any function with the change of the date and declare the function in your ts.
To change the format of the date :
Add this to
app.module.ts
:Add the below in providers of
app.module.ts
:I am working in Angular 7 Implementation is as follows.
Declare event in your class as follows.
@Output() dateChange:EventEmitter< MatDatepickerInputEvent< any>>;
Remember you should have material module already Installed. Create one method in typescript file as follows.
someMethodName(date: any) {
//your code here
}
your html file matinput will be like below
from docs you can use one of the below events based on your requirement
Emits when a change event is fired on this .
Emits when an input event is fired on this .
For example:
or