Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

dynamic set required in angular using formcontrol

onAddValidationClick(){
    this.formGroup.controls["firstName"].setValidators(Validators.required);
    this.formGroup.controls["firstName"].updateValueAndValidity();
}

onRemoveValidationClick(){
    this.formGroup.controls["firstName"].clearValidators();
    this.formGroup.controls["firstName"].updateValueAndValidity();
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dynamic #set #required #angular #formcontrol
ADD COMMENT
Topic
Name
6+2 =