Created
June 5, 2018 07:55
-
-
Save ball6847/9a3930f5d45477c95de7ac8b0e753bfd to your computer and use it in GitHub Desktop.
create component wrap form control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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