nestedControl<T> method

AbstractControl<T> nestedControl<T>(
  1. String name
)

Returns the AbstractControl with the given name, supporting nested paths. E.g. "address.street" will return the "street" control inside the "address" group. Supports multiple levels of nesting. Throws if any part of the path is invalid.

Implementation

AbstractControl<T> nestedControl<T>(String name){
  if(name.contains('.')){
    final parts = name.split('.');
    AbstractControl current = this;
    for(final part in parts){
      if(current is! FormGroup) {
        throw DartNgFormsException('Invalid nested control path: "$name". Part "$part" is not a FormGroup.');
      }
      final next = current.controls[part];
      if(next == null) {
        throw DartNgFormsException('Control "$part" not found in FormGroup.');
      }
      current = next;
    }
    return current as AbstractControl<T>;
  }
  if(!contains(name)) {
    throw DartNgFormsException('Control "$name" not found in FormGroup.');
  }
  return controls[name] as AbstractControl<T>;
}