You can use the setValidators
method as follows:
// Para utilizar uma validação
this.formulario.controls.CodigoTemp.setValidators([
Validators.required,
]);
// Para remover as validações
this.formulario.controls.CodigoTemp.setValidators(null);
Remember that this method will replace all existing validations, in case you remove the validations, no problem. If you want to add a new validation, for example, maxLength
, you should redefine the existing validations and the new validation you want, like this:
this.formulario.controls.CodigoTemp.setValidators([
Validators.required,
Validators.maxLength(50),
]);
As far as I could find, there is still no functionality to add validations, such as discussed here . p>