-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed
Labels
Milestone
Description
🚀 feature request
Relevant Package
This feature request is for @angular/forms
Description
FormGroup has the methods addControl and registerControl, which allow you to add a control with and without emitting an event respectively. However, to remove a control there is only the removeControl method. Currently the cleanest way to remove a control without emitting an event is to delete it directly from the controls object and manually call _registerOnCollectionChange on the removed control.
Describe the solution you'd like
Two possible solutions:
- Add a method called
unregisterControlthat mirrorsregisterControl. - Add an optional parameter to
addControlandremoveControle.g.options: {emitEvent?: boolean} = {}and deprecate theregisterControlmethod.
Describe alternatives you've considered
A workaround is to manually delete the control:
const form = new FormGroup({ foo: new FormControl() });
// to remove the control:
form.removeControl('foo');
// this is required in order to avoid emitting an event:
const controlToRemove = form.get('foo') as FormControl;
controlToRemove._registerOnCollectionChange(() => {});
delete form.controls['foo'];Reactions are currently unavailable