Cannot call FormGroup removeControl method without emitting an event
See original GitHub issueπ 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
unregisterControl
that mirrorsregisterControl
. - Add an optional parameter to
addControl
andremoveControl
e.g.options: {emitEvent?: boolean} = {}
and deprecate theregisterControl
method.
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'];
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Select box not updating the UI after remove control of reactive ...
The problem is when I try to remove a feature column in between the first and the last feature column, the formControl is...
Read more >FormGroup - Angular
This method does not update the value or validity of the control. ... Specifies whether this FormGroup instance should emit events after a...
Read more >FormGroup in Angular - TekTutorialsHub
The FormGroup is one of the building blocks of the angular forms. ... When false, no events are emitted. ... removeControl(). This method...
Read more >Angular FormGroup addControl() and removeControl()
The form control can be FormGroup , FormControl and FormArray . Find the methods of FormGroup used to add, update or remove controls....
Read more >Reactive Forms Part 16 | Form Arrays removeAt method
In this video, you will learn how to remove a form controls from an array using removeAt method.To Know more about reactive forms,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
OK Ivy is out now, any chance we could get any action on this before everything is put on hold again to develop the next latest and greatest version?
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.