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

implementing a convert to a timestamp on the fly #11

Closed kvzhkv closed 5 years ago

kvzhkv commented 7 years ago

Hi, I need a timestamp value in my formControl and trying to implement it with your great useValueAsDate directive. (Thanks!!!) I actually have updated writeValue() to update value in the view like this:


  writeValue(value: number): void {
    if (!value) {
      this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', null);
      return;
    }
    this._renderer.setElementProperty(this._elementRef.nativeElement, 'valueAsDate', this.convertFromTimestamp(value));
  }

  convertFromTimestamp(value: number): Date {
    return new Date(value);
  }

but how to convert date value from input to model? I realize that registerOnChange() should be updated, but how? Does anybody have an ideas?

JohannesHoppe commented 5 years ago

This feature goes beyond the necessary functionality. A conversion to a timestamp can be done elsewhere in the code.