angular reactive form check if control is required code example
Example: angular check if control has required validator
import { AbstractControl } from '@angular/forms';
export const isControlRequired = (control: AbstractControl): boolean => {
if (!control) {
return false;
}
if (control.validator) {
const validator = control.validator({} as AbstractControl);
if (validator && validator.required) {
return true;
}
}
return false;
};