I'm implement datepicker on my form, with help from 3rd party datepicker library (jQuery, etc). It works when user select the date, but Angular can't detect change emmited from datepicker (e.g. when I choose date).
Here is my code :
HTML
<input type="text" id="dateOfBirth" name="dateOfBirth" formControlName="dateOfBirth" value="{{selectedEmployee.dateOfBirth}}" (ngModelChange)="dateFieldChanged()" readonly>
TS
dateFieldChanged() {
console.log('date changed!');
}
It supposed to execute dateFieldChange(), isn't it? So that I can determine whether form still pristine or already dirty. But the method never executed.
I assume it's because 3rd party datepicker javascript that change the value, so that Angular not detect it.
How to work around this problem?
I've managed to do it. Since I'm targetting modern browser (!= IE8 below), I only need to change the input type to be "date"
<input type="date" id="dateOfBirth" name="dateOfBirth" formControlName="dateOfBirth" value="{{selectedEmployee.dateOfBirth}}" (ngModelChange)="dateFieldChanged()">