Sitelet https://web.archive.org/web/20250822194942/https://github.com/angular/angular/issues/39732
Skip to content

Forms: better handling of internal onCollectionChange callbacks #39732

@AndrewKushnir

Description

@AndrewKushnir

Form controls have internal API that allows subscribing to changes in a data collection of FormGroups and FormArrays (when a new control is added to a collection or existing one is removed). This internal API is used inside FormGroupDirective to trigger DOM updates. The problem with the current API is that there is no way to append a callback or remove a particular one (for ex. a callback that belongs to a directive that is being removed). Instead, new onCollectionChange callback always resets existing one.

We should consider updating the logic that handles onCollectionChange callback to provide an ability to add and remove
particular callbacks without affecting previous callbacks, similar to what we have for onChange callbacks. That should help implement more granular management of the onCollectionChange callbacks.

Note: this change would be backwards-incompatible since some exiting code may rely on the fact that the onCollectionChange callback is getting rewritten. There is a PR #39685 that implements the change proposed in this ticket.

Metadata

Metadata

Assignees

Labels

P4A relatively minor issue that is not relevant to core functionsarea: formsbreaking changes

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions