-
-
Save jorroll/4fd2d16d7796771de1a27930b80e011b to your computer and use it in GitHub Desktop.
This file contains 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({ | |
template: ` | |
<div> | |
<label>First name</label> | |
<input | |
[value]="control.value" | |
(valueChange)="onChange($event)" | |
(blur)="onTouched()" | |
[required]="required" | |
[disabled]="control.disabled" | |
/> | |
</div> | |
`, | |
providers: [ | |
{ | |
provide: NG_CONTROL_ACCESSOR, | |
useExisting: forwardRef(() => FirstNameInputComponent), | |
multi: true, | |
}, | |
], | |
}) | |
export class FirstNameInputComponent implements ControlAccessor { | |
@Input() required = false; | |
readonly control = new FormControl(''); | |
onChange(value: any) { | |
this.control.markChanged(true); | |
this.control.setValue(value); | |
} | |
onTouched() { | |
this.control.markTouched(true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment