Ngx-bootstrap: ISO dates loaded to the reactive forms are showing invalid date

Created on 16 Mar 2018  路  6Comments  路  Source: valor-software/ngx-bootstrap

Bug description or feature request:

when an ISO date format is loaded to a reactive model it shows an invalid date.

Plunker/StackBlitz that reproduces the issue:

https://stackblitz.com/edit/angular-dpshux

Versions of ngx-bootstrap, Angular, and Bootstrap:

ngx-bootstrap: 2.0.3

Angular: 5.2.8

Bootstrap: 4.0

Build system: Angular CLI, System.js, webpack, starter seed:

Angular CLI 1.7.3

comp(datepicker)

Most helpful comment

What's the rational behind making the property strict to Date type? No service will provide you a date property in the type Date so it is literally causing us to write unnecessary code to instantiate a date object with the property of the ISO date string. It should just allow to accept both (Date | string)

All 6 comments

Datepicker model format is a Date object and you provided a string. This string has to be converted into a Date object before using it in datepicker.

It used to work with version 2.0.beta8

@IlyaSurmay I think this should be reopened, datepicker should work with iso strings. Otherwise I have to process every date in the output from an api.

agreed with the above; this means we can't just materialize from json and bind with ngModel, we have to transform it. And it means that in typescript, if I expect it to be materialized as a string, but datepicker needs it as a Date, then I have to set that field in the dto's interface to type any so that I can assign a Date to it programmatically on load, and that's just weird.
Is this really the intent/policy of this project? I notice that writeValue(value: Date | string)...

What's the rational behind making the property strict to Date type? No service will provide you a date property in the type Date so it is literally causing us to write unnecessary code to instantiate a date object with the property of the ISO date string. It should just allow to accept both (Date | string)

This should reopened. This is really weird behavior. I am using reactive forms & facing the exact same issue. Any updates on this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Scooviese picture Scooviese  路  3Comments

RolfVeinoeSorensen picture RolfVeinoeSorensen  路  3Comments

haisaco picture haisaco  路  3Comments

ctrl-brk picture ctrl-brk  路  3Comments

ghiscoding picture ghiscoding  路  3Comments