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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fire change events upon initialization #17398
Comments
This seems a little arbitrary because we've had multiple issues in the past where people have requested the exact opposite: only dispatching change events if the value changed as the result of a user action. |
I searched for prior issues on this topic and found #1125 which refers to inconsistency rather than strictly change-on-init or not. In that issue, I noticed that @jelbourn stated that change-on-init was unequivocally a bug, and I'm interested in hearing the reasoning behind that design decision. I think that firing a change event on init when defaults are set is the more flexible approach, since users could:
|
@crisbeto I'd be happy to start work on a PR with these changes once we have a solid plan of what needs to be done! |
Yeah, I'd agree with @crisbeto. I think our understanding of this was that we want to match native elements as much as possible. i.e. See: https://stackblitz.com/edit/comp-17398?file=src/app/app.component.ts |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage. We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package. You can find more details about the feature request process in our documentation. |
We're in the process of cleaning up our issue backlog. I'll close this issue, because there hasn't been any activity in a long time and the current behavior is intentional. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Feature Description
Components that have change events should fire them when their initial value it set.
Use Case
This would let reactive observers of that value receive an initial value, making
BehaviorSubject
s able to be used to track component state.Currently, to find the value of a component just after init, the component must be injected into its parent using
@ViewChild
and then the value must be manually extracted.Otherwise, the
BehaviorSubject
's initial value must be specified in the component's code as well as in the component's template, which is prone to becoming desynchronized during refactoring due to the duplicated code.A concrete use case example
I want to receive
MatPaginator
page events to update my query. I don't want to have to manually trigger it the first time because that would require an additional layer of event handling and/or some spaghetti code, it should just be triggered like every other change event since the value is changing from being absent to being present.Implementation Considerations
This could be a flag that defaults to
false
to prevent breaking existing applications, but I don't think many existing applications would break from this change unless their event handling is very fragile.The text was updated successfully, but these errors were encountered: