-
Notifications
You must be signed in to change notification settings - Fork 25k
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
feat(router): emit activate/deactivate events when an outlet gets attached/detached #43333
feat(router): emit activate/deactivate events when an outlet gets attached/detached #43333
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the meaning of the activate
and deactivate
events. The attach
and detach
are similar but not exactly the same. Especially when comparing detach
with deactivate
, the deactivate
emits after the component is destroyed.
In fact, this behavior is specifically documented by the activate
and deactivate
events.
A router outlet emits an activate event when a new component is instantiated,
and a deactivate event when a component is destroyed.
This change is contrary to the documented behavior. Please open a feature request for new events attached
and detached
rather than changing the meaning of the current activate
and deactivate
events.
Thanks! Good point, by creating new outputs we avoid also potential breaking changes. |
514990f
to
ca8a4dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note that it would be nice to mention a use-case for this feature either in the commit message or a resolved issue.
Edit: For example, another option in #43251 would be to use the outlet context's onAttached event rather than the Router's events
onNavBackToCachedComponent(outletName: string) {
const context = this.contexts.getContext(outletName);
context.outlet.attachedEvents.pipe(take(1)).subscribe(() => {
// Do something
});
ca8a4dd
to
a81a690
Compare
a81a690
to
3851e42
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🍪
reviewed-for: public-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for api changes! Thank you, @dimakuba. This is a nice addition.
Reviewed-for: public-api
…ached/detached Previously the events of `RouterOutlet` (activate/deactivate) were not fired when an outlet got attached/detached with `RouteReuseStrategy`. The changes configure `RouterOutlet` to emit events when an outlet gets attached/detached. Fixes angular#25521, angular#20501
3851e42
to
7cbbf26
Compare
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. |
Previously there was no way to subscribe for
attach
/detach
events from theRouterOutlet
when an outlet got attached/detached withRouteReuseStrategy
. The changes add new outputsattached
/detached
for theRouterOutlet
to emit events when an outlet gets attached/detached.