@stencil/angular-output-target
Version:
Angular output target for @stencil/core components.
40 lines (31 loc) • 948 B
text/typescript
import { Directive, ElementRef, HostListener } from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';
({})
export class ValueAccessor implements ControlValueAccessor {
private onChange: (value: any) => void = () => {/**/};
private onTouched: () => void = () => {/**/};
protected lastValue: any;
constructor(protected el: ElementRef) {}
writeValue(value: any) {
this.el.nativeElement.value = this.lastValue = value == null ? '' : value;
}
handleChangeEvent(value: any) {
if (value !== this.lastValue) {
this.lastValue = value;
this.onChange(value);
}
}
('focusout')
_handleBlurEvent() {
this.onTouched();
}
registerOnChange(fn: (value: any) => void) {
this.onChange = fn;
}
registerOnTouched(fn: () => void) {
this.onTouched = fn;
}
setDisabledState(isDisabled: boolean) {
this.el.nativeElement.disabled = isDisabled;
}
}