New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReactiveForms: FormGroup.removeControl doesn't call control.setParent(null) #29517
Comments
Trying to fix this, I just noticed that Also found a reference to issue #24571 on the |
When a control is removed from a FormGroup, or replaced by another control, that control's parent wasn't cleared. Apart from leaving the parent reference on the removed control, this also made it impossible to react on the control being removed from an overridden setParent. This change introduces an unregisterControl method, symmetric to registerControl, which is called to clear a control's parent (set to null) when it's removed or replaced. PR Close angular#29517
When a control is removed from a FormGroup, or replaced by another control, that control's parent wasn't cleared. Apart from leaving the parent reference on the removed control, this also made it impossible for the control to react on its removal in an overridden setParent. This change introduces an unregisterControl method, symmetric to registerControl, which is called to clear a control's parent (set to null) when it's removed or replaced. PR Close angular#29517
@mbinic Sounds all fine to me. |
Sorry @Airblader, I don't understand - are you saying that the original behavior is fine (i.e. no change is needed), or that assigning |
That your PR changes sound fine :-) |
馃悶 bug report
Affected Package
@angular/forms
Is this a regression?
Most probably no.
Description
The
FormGroup
class'removeControl
method does not callsetParent(null)
for the target control. This appears to be an inconsistency in the implementation.Our expectation is that
removeControl
would callcontrol.setParent(null)
, to clear the control's parent once detached. This would also make it symmetric withaddControl
.Use case
We have a dynamic form implementation where a class extending
FormGroup
is dynamically attaching/detaching child groups/controls usingaddControl
/removeControl
. The controls can react to their inclusion/exclusion in theirsetParent
method (to e.g. subscribe to a parent'sattachedState
observable).Since we're extending
FormGroup
this is easy to work around by just overridingremoveControl
, but IMHO the inconsistency in the framework should be fixed.馃敩 Minimal Reproduction
The call is missing from: https://github.com/angular/angular/blob/master/packages/forms/src/model.ts#L1298 .
馃敟 Exception or Error
None.
馃實 Your Environment
Angular Version: 7.2.0
Anything else relevant?
No.
The text was updated successfully, but these errors were encountered: