remove method
Removes control
from the array.
The argument control
is the child control to remove.
When updateParent
is true or not supplied (the default) each change
affects this control and its parent, otherwise only affects to this
control.
When emitEvent
is true or not supplied (the default), both the
statusChanges and valueChanges emit events with the latest status
and value when the control is reset. When false, no events are emitted.
Throws FormControlNotFoundException if control
is not a child control
of the array.
Example
final array = FormArray<String>([
FormControl<String>(value: 'John'),
FormControl<String>(value: 'Doe'),
]);
print(array.value) // outputs: ['John', 'Doe']
print(array.controls.length) // outputs: 2
final firstControl = array.control('0');
array.remove(firstControl);
print(array.value) // outputs: ['John']
print(array.controls.length) // outputs: 1
Implementation
void remove(
AbstractControl<T> control, {
bool emitEvent = true,
bool updateParent = true,
}) {
final index = _controls.indexOf(control);
if (index == -1) {
throw FormControlNotFoundException();
}
removeAt(index, emitEvent: emitEvent, updateParent: updateParent);
}