Closed peterdeme closed 7 years ago
Update: looks like this is happening in drainMicroTaskQueue()
function of zone.js
Anyways, I used an ugly workaround to resolve this. (I used ngModel as a string instead of Date object)
Sorryt for the confusion, and thanks for reporting it. Fix will come in 5 min.
Thanks so much!
Hi,
So my datetime picker's ngModel can be changed by another form control. And when the model is changed the input element's value is not getting formatted anymore.
<input [(ngModel)]="expiration" ng2-datetime-picker date-only="true" [min-date]="contractEndMinDate" [max-date]="contractEndMaxDate" date-format="MMM DD, YYYY" />
So whenever myexpiration
variable (which is aDate
type) is getting changed by another form control, the input just becomes the string representation. For example:Sun May 28 2017 16:16:16 GMT+0200 (Central Europe Daylight Time)
. The default value is getting updated properly though. Any idea why is my formatting not getting applied or how can I debug it?Is it because of this line? https://github.com/ng2-ui/ng2-datetime-picker/blob/master/src/ng2-datetime-picker.directive.ts#L192 Maybe this line needs to be applied on every ngOnChange?
this.ngModel.toString = () => Ng2Datetime.formatDate(this.ngModel, this.dateFormat, this.dateOnly);
Fun fact: during the ngOnInit of my app component, the expiration variable is getting changed and the input value is formatted properly. But whenever it is getting changed by another element, formatting is not working anymore. Also: of course I have momentjs loaded, that's not the issue.
Thanks