JohannesHoppe/angular-date-value-accessor

implementing a convert to a timestamp on the fly

kvzhkv opened this issue · 1 comments

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?

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