JohannesHoppe / angular-date-value-accessor

Home of the Angular DateValueAccessor for <input type="date">
http://johanneshoppe.github.io/angular-date-value-accessor/
MIT License
78 stars 19 forks source link

Initial value null #3

Closed ghost closed 7 years ago

ghost commented 7 years ago

My init value was null and writeValue failed.

i wrote if(value != null) this._renderer.setElementProperty(this._elementRef.nativeElement, 'valueAsDate', value);

JohannesHoppe commented 7 years ago

Good point. Im not sure about the exact behviour. I would clear the value instead. I will fix that in a timely manner

JohannesHoppe commented 7 years ago

(which means 1-2 weeks, since I need to finish a super-urgent project first)

iwes commented 7 years ago

I ended up using the following, as the dates being passed in were not true Date objects:

    writeValue(value: Date): void {
        if (value != null) {
            this._renderer.setElementProperty(this._elementRef.nativeElement, 'valueAsDate', new Date(value));
        }
    }

If it becomes necessary for my project, I'll do more work to check that the input value resolves to a valid Date before attempting to set it.

JohannesHoppe commented 7 years ago

closed by #5

JohannesHoppe commented 7 years ago

Thanks! v0.0.2 is available on NPM. Please report any errors, if required.