#handling invalid on custom form control component

1 messages · Page 1 of 1 (latest)

jaunty fog
#

Angular will add an ng-invalid css class to the host element of your component. You can use that class to display a red border.

viral mauve
#

ok that works for now. but what if i need more logic to do

viral mauve
#

nevermind doesnt work. ng-invalid gets appended to all controls under the formgroup

jaunty fog
#

Not sure which form group you're talking about. As always, a complete minimal repro would help.

viral mauve
#
form = this.fb.group({
  field1: ['test', { validators: Validators.required ],
  field2: [null, { validators: Validators.required ]
})

in this case both fields gets ng-invalid since theyre under the same form group which is invalid. i need to show the error border on the only on field thats invalid only (field2)