ng2-ui / datetime-picker

Angular2 DateTime Picker
https://ng2-ui.github.io/#/datetime-picker
MIT License
121 stars 62 forks source link

Input not getting formatted on ngModel change #123

Closed peterdeme closed 7 years ago

peterdeme commented 7 years ago

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 my expiration variable (which is a Date 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

peterdeme commented 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)

allenhwkim commented 7 years ago

Sorryt for the confusion, and thanks for reporting it. Fix will come in 5 min.

peterdeme commented 7 years ago

Thanks so much!