Skip to content

Instantly share code, notes, and snippets.

@ball6847
Created June 5, 2018 07:55
Show Gist options
  • Save ball6847/9a3930f5d45477c95de7ac8b0e753bfd to your computer and use it in GitHub Desktop.
Save ball6847/9a3930f5d45477c95de7ac8b0e753bfd to your computer and use it in GitHub Desktop.
create component wrap form control
@Component({
selector: 'my-wrapper',
template: '<input ngDefaultControl>',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => NumberInputComponent),
multi: true,
},
],
})
export class MyWrapper implements ControlValueAccessor {
@ViewChild(DefaultValueAccessor) private valueAccessor: DefaultValueAccessor;
writeValue(obj: any) {
this.valueAccessor.writeValue(obj);
}
registerOnChange(fn: any) {
this.valueAccessor.registerOnChange(fn);
}
registerOnTouched(fn: any) {
this.valueAccessor.registerOnTouched(fn);
}
setDisabledState(isDisabled: boolean) {
this.valueAccessor.setDisabledState(isDisabled);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment