ngx-bootstrap: Datepicker showing 'Invalid date' on ISO date from server.
Bug description or feature request:
Can you please re-open this issue: #4020
The datepicker shows ‘Invalid date’ on data from the server. Why can’t it parse an ISO date?
I shouldn’t need to write code like this just for the datepickler:
this.httpClient.get<ProjectDescription>('/api/Get/SomeData/').toPromise()
.then(result => {
this.item= result;
this.item.startDate = new Date(this.item.startDate);
Versions of ngx-bootstrap, Angular, and Bootstrap:
ngx-bootstrap:
3.0.1
Angular:
6.0.7
Bootstrap:
3.3.7
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 8
- Comments: 25 (1 by maintainers)
Having the same issue. Using
new Date()does make it display correctly but also make the form control value an Object which then causes problems when submitting the form.The only way I’ve found to make it work correctly is to use the date pipe on the value.
+1
Any update on this issue? datepicker used to allow setting ISO string as the ngModel value… why has this been changed? Requires an unnecessary rewrite to instantiate the date object…
Solved with date pipe
[ngModel]="user.birthDate | date: 'MM/dd/yyyy'"but when i try using
| date: 'yyyy-MM-dd'not worked, this format get default browser date format intype="date"and here it doesn’t work seriously interesting if it didin my case, I had to add a redundant timepicker like so
<timepicker [(ngModel)]="license.expiry_date" [ngModelOptions]="{standalone: true}" style="display: none;"></timepicker>I solved this problem by creating my own date picker component that wraps ngx-bootstrap version and handles conversion from string to date. However this feature should indeed be included in ngx-bootstrap component itself. I was really surprised it hasn’t been done already.
Hi guys
All your answers is wrong!!!
For example , we have customized EN->RU locale:
Yes sure,it’s not interesting for us.
Angular any time supported: string->date->string->any and conversely!
We can anything do it with moment package : date<->string conversion.
TS
HTML
Model:
UI
I know this problem not last ,all version have. bs 3 and 4 ,now I have using with angular 8 and bs 4. Last 3yr same issue (DE locale same issue), now its fine works.
+1
@Et3rnal
I’ve switched to the angular material datepicker, this supports ISO strings: https://material.angular.io/components/datepicker/overview#setting-the-selected-date