Skip to content

Instantly share code, notes, and snippets.

Created September 25, 2020 21:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Form Field Component
<div [formGroup]='formGroup'>
<label [attr.for]='field.key'>{{field.title}}:</label>
<div [ngSwitch]="field.type" class='field-group'>
<div *ngSwitchCase="'text'">
<input type='text' [formControlName]="field.key" [id]='field.key' />
<div class='error-message' *ngIf='!isValid' role="alert">{{field.title}} is required</div>
export class FormFieldInputComponent implements OnInit {
@Input() field: ContactFormField
@Input() formGroup: FormGroup;
constructor() { }
ngOnInit(): void {
get isValid() {
return this.formGroup.controls[this.field.key].valid || this.formGroup.controls[this.field.key].untouched;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment