/ / Vstupná smernica uhlového 2 nezúčtuje svoju hodnotu zobrazenia pri resetovaní formulára - uhlové, angulárne2-formy, angular2-smernice

Úhlová 2 vstupná smernica nevyčisáva svoju hodnotu pohľadu na obnovenie formátu - uhlovú, uhlovú2-formu, angular2-directives

Mám nasledujúcu smernicu:

declare  var $:any;

export const CUSTOM_INPUT_DATE_PICKER_CONTROL_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => SharedAppDatePickerDirective),
multi: true
};

@Directive({
selector: "[date-picker]",
host: {"(blur)": "onTouched($event)"},
providers: [CUSTOM_INPUT_DATE_PICKER_CONTROL_VALUE_ACCESSOR]
})
export class SharedAppDatePickerDirective implements     ControlValueAccessor, OnInit {

constructor(private el: ElementRef) { }

private innerValue: string;

public onChange: any = (_) => { /*Empty*/ }
public onTouched: any = () => { /*Empty*/ }

ngOnInit() {

$(this.el.nativeElement).datepicker().on("change", e => this.onChange(e.target.value)).on("change", e => e.target.focus());
}

get value(): any {
return this.innerValue;
};

//set accessor including call the onchange callback
set value(v: any) {
if (v !== this.innerValue) {
this.innerValue = v;
this.onChange(v);
}
}

writeValue(val: string) : void {
this.innerValue = val;
}

registerOnChange(fn: any): void {
this.onChange = fn;
}

registerOnTouched(fn: any): void {
this.onTouched = fn;
}

ngOnDestroy() {
$(this.el.nativeElement).datepicker("destroy");
}
}

Keď form.reset() nastane, formulárové kontroly, na ktoré sa táto smernica vzťahuje, nevyjadrujú jej hodnotu zobrazenia. po form.reset() stáva sa nedotknutou, nedotknutou, neplatnou, ale zachováva hodnotu, ktorú som predtým napísal.

Nejaké nápady, ako sa vysporiadať?

odpovede:

0 pre odpoveď č. 1

Opravené, že tým, že:

writeValue(val: string) : void {
this.innerValue = val;
this.el.nativeElement.value = val;
}