In Angular 4 app I have a form model like this:
this.form = this._fb.group({
title: [\'\', [Validators.required, Validators.minLength(3), Validators.maxLengt
To Add Validators:
this.form = this._fb.group({
title: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(50)]],
description: ['', [Validators.required, Validators.minLength(3)]]
});
or
this.form.get('title').setValidators([Validators.required,Validators.minLength(3),
Validators.maxLength(50)]);
To Remove the 'Required' validator only, you can reset the validators.
saveDraft() {
this.form.get('title').setValidators([Validators.minLength(3), Validators.maxLength(50)]);
this.form.get('title').updateValueAndValidity();
}
updateValueAndValidity determines how the control propagates changes and emits events when the value and validators are changed