Skip to content

Instantly share code, notes, and snippets.

@jorroll
Last active November 4, 2019 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorroll/4fd2d16d7796771de1a27930b80e011b to your computer and use it in GitHub Desktop.
Save jorroll/4fd2d16d7796771de1a27930b80e011b to your computer and use it in GitHub Desktop.
@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