Currently, I am facing a challenge in breaking an iterative loop and returning false when a specific condition is met.
Essentially, my goal is to determine whether a reactive form is empty or not:
public isEmpty(form: AbstractControl): boolean {
if (form instanceof FormGroup) {
for (const key of Object.keys(form.controls)) {
if (key !== 'modalite') {
const control = form.get(key);
if (control instanceof FormGroup) {
this.isEmpty2(control);
} else {
if (control.value && control.value !== '') {
return false;
}
}
}
}
} else {
if (form.value && form.value !== '') {
return false;
}
}
return true;
}
The issue lies in the fact that my "return false" statement breaks out of the for loop but still continues iterating thereafter, resulting in always returning true. My aim is to return false and stop the iteration as soon as a non-empty form control is encountered. Any insights on how to achieve this would be greatly appreciated. Thank you!