Skip to content
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

ApplicationRef's onDestroy method should not be internal #49087

Closed
edusperoni opened this issue Feb 15, 2023 · 5 comments
Closed

ApplicationRef's onDestroy method should not be internal #49087

edusperoni opened this issue Feb 15, 2023 · 5 comments
Labels
area: core Issues related to the framework runtime core: bootstrap feature: in backlog Feature request for which voting has completed and is now in the backlog feature Issue that requests a new feature state: has PR
Milestone

Comments

@edusperoni
Copy link
Contributor

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

When developing with NgModules we were able to do:

const moduleRef = await platformBrowserDynamic().bootstrapModule(AppModule);
moduleRef.onDestroy(() => { /* some logic */ });

The new bootstrapApplication now returns a ApplicationRef. Although the onDestroy method exists in ApplicationRef, it's marked as internal and not exposed.

Proposed solution

Make ApplicationRef.onDestroy not internal and part of the public API. This makes sense as well because .destroy() and .destroyed are part of the public API.

Alternatives considered

(applicationRef as any).onDestroy(() => {});

or getting the reference to the first component and using its onDestroy.

@JeanMeche
Copy link
Member

FYI, making onDestroy public has been discussed as part of #45624.

@AndrewKushnir wasn't opposed to making it public if a use case arises !

@AndrewKushnir AndrewKushnir added feature Issue that requests a new feature area: core Issues related to the framework runtime labels Feb 16, 2023
@ngbot ngbot bot added this to the Backlog milestone Feb 16, 2023
@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Feb 16, 2023
@angular-robot
Copy link
Contributor

angular-robot bot commented Feb 16, 2023

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

@edusperoni
Copy link
Contributor Author

@AndrewKushnir if you're fine with it, I can do the PR to expose it. We use it in NativeScript to manage the Angular bootstrap and application launch/exit events.

@AndrewKushnir
Copy link
Contributor

@edusperoni yes, that makes sense, feel free to open a PR 👍

@AndrewKushnir AndrewKushnir added feature: in backlog Feature request for which voting has completed and is now in the backlog and removed feature: votes required Feature request which is currently still in the voting phase labels Feb 19, 2023
pkozlowski-opensource added a commit to pkozlowski-opensource/angular that referenced this issue Apr 3, 2023
This change exposes the onDestroy callback on the ApplicationRef
as the public API. It is useful for cases where people need to
execute cleanup logic on application teardown.

Closes angular#49087
@dylhunn dylhunn closed this as completed in a5f1737 Apr 3, 2023
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime core: bootstrap feature: in backlog Feature request for which voting has completed and is now in the backlog feature Issue that requests a new feature state: has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants