angular formgroup controls code example
Example 1: formgroup addcontrol
let form: FormGroup = new FormGroup({});
form.addControl(field_name, new FormControl('', Validators.required));
Example 2: update formgroup value angular
To set all FormGroup values use, setValue:
this.myFormGroup.setValue({
formControlName1: myValue1,
formControlName2: myValue2
});
To set only some values, use patchValue:
this.myFormGroup.patchValue({
formControlName1: myValue1,
});
Example 3: formgroup angular
content_copy
const form = new FormGroup({
first: new FormControl('Nancy', Validators.minLength(2)),
last: new FormControl('Drew'),
});
console.log(form.value);
console.log(form.status);