I am creating an application in Angular (4.0) that contains form ( FormGroup
). In this form, I have an email input (s FormControl
) and I use Validators.email
to validate.
import { Validators } from '@angular/forms';
let validators = [];
if ([condition]) {
validators.push(Validators.email);
}
let fc = new FormControl([value] || '', validators);
But when the input is empty, it is invalid (it has a class ng-invalid
), even if it is not required.
Is this the right behavior? What can I do?
source
share