Skip to content
This repository was archived by the owner on Mar 2, 2018. It is now read-only.

Commit 54c1a8d

Browse files
committed
issue #143, applied timed-out ngmodel change for formatting value when program assigns ngModel value as string
1 parent 03ddc31 commit 54c1a8d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/ng2-datetime-picker.directive.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,20 @@ export class Ng2DatetimePickerDirective implements OnInit, OnChanges {
171171
date = changes['ngModel'].currentValue;
172172

173173
if (date && typeof date !== 'string') {
174-
date.toString = () => Ng2Datetime.formatDate(date, this.dateFormat, this.dateOnly);
174+
date.toString = () => Ng2Datetime.formatDate(date, this.dateFormat, this.dateOnly);
175+
this.setInputElDateValue(date);
176+
this.updateDatepicker();
177+
} else if (date && typeof date === 'string') {
178+
/** if program assigns a string value, then format to date later */
179+
setTimeout( () => {
180+
let dt = this.getDate(date);
181+
dt.toString = () => Ng2Datetime.formatDate(dt, this.dateFormat, this.dateOnly);
182+
this.ngModel = dt;
183+
this.inputEl.value = ''+dt;
184+
})
175185
}
176186
}
177187

178-
this.setInputElDateValue(date);
179-
this.updateDatepicker();
180188
}
181189

182190
updateDatepicker() {

0 commit comments

Comments
 (0)