Closed hhntpp closed 4 years ago
Let me separate this into 2 issues:
The provided value is not a Date
you used types of Date? Are you sure? If yes, please provide a plunkr / jsfiddle so that I investigate.I'm sorry for I could not provide plunkr/jsfiddle, because I don't know how to attach your date-value-accessor to plunkr/jsfiddle.
Sorry, I can't help with that. My time is rare right now!
Getting same 404 error. @hhntpp what did you add to systemjs.config.js?
I used SystemJS to load files. It had error: Failed to load resource: the server responded with a status of 404 (Not Found) /angular-date-value-accessor I found the solution: add config to file systemjs.config.js. You should change the help config for this case.
My template used: <input type="date" [(ngModel)]="user.Birthday" useValueAsDate> with datatype of Birthday: Date; It could run with no error (console log no error, and I had set user.Birthday = new Date() in constructor ), when I set user.Birthday = new Date() in a click event button, and console log of Chrome had multi errors: Uncaught (in promise): TypeError: Failed to set the 'valueAsDate' property on 'HTMLInputElement': The provided value is not a Date. TypeError: Failed to set the 'valueAsDate' property on 'HTMLInputElement': The provided value is not a Date. at DomRenderer.setElementProperty (node_modules/@angular/platform-browser/bundles/platform-browser.umd.js:3070:45) at DateValueAccessor.writeValue (node_modules/angular-date-value-accessor/date-value-accessor.js:27:24) ...
Although it thrown error, the value of user.Birthday still got the date from input control and vice versus.
I found your date-accessor from http://stackoverflow.com/questions/37055311/angular2-how-to-use-javascript-date-object-with-ngmodel-two-way-binding I tried some solutions in that post, they had problems when inputted value of year by keypress. Your solution doesn't have that problem. I hope you check your project and fix this error.