angular check if control has required validator

Solutions on MaxInterview for angular check if control has required validator by the best coders in the world

showing results for - "angular check if control has required validator"
Jaxon
10 Aug 2017
1import { AbstractControl } from '@angular/forms';
2
3export const isControlRequired = (control: AbstractControl): boolean => {
4  if (!control) {
5    return false;
6  }
7
8  if (control.validator) {
9    const validator = control.validator({} as AbstractControl);
10    if (validator && validator.required) {
11      return true;
12    }
13  }
14
15  return false;
16};