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

request| feat(NgModule): provide life cycle hooks #10244

Closed
PatrickJS opened this issue Jul 22, 2016 · 4 comments
Closed

request| feat(NgModule): provide life cycle hooks #10244

PatrickJS opened this issue Jul 22, 2016 · 4 comments
Labels
area: core Issues related to the framework runtime core: NgModule feature Issue that requests a new feature freq1: low
Milestone

Comments

@PatrickJS
Copy link
Member

PatrickJS commented Jul 22, 2016

With the introduction of NgModule to solve some problems of having to run code before bootstrap. I think it's better to provide lifecycle hooks for these modules for example theses would be great to have

ngBeforeLoad: before loading the module
ngAfterLoad: after the module is loaded
ngBeforeChangeDetection: do something before change detection happens for this module
ngAfterStable: do something after the zones are stable (a great use-case for this is prefetching async lazy routes after boot that doesn't affect the ui)

ngAfterStable is probably the best feature since universal and jasmine can use it

might also help with #9975
also see ng1 .config and .run angular/angular.js#4003

@lacolaco
Copy link
Contributor

lacolaco commented Jul 25, 2016

IMHO, the constructor of the module class is usable as ngBeforeLoad.
And the bootstrap() function returns a promise that can be used as ngAfterLoad.

ngAfterStable can be replaced by using NgZone and ngZone.onStable.

@PatrickJS
Copy link
Member Author

The benefit of having these lifecycle hooks is giving control back to the developer for modules. For example, if a 3rd party modules does something async in the constructor there's no way to track it or even know there was an async call. If there was an async method then you would know to invoke it.

@PatrickJS PatrickJS changed the title request| feat(AppModule): provide life cycle hooks request| feat(NgModule): provide life cycle hooks Aug 18, 2016
@tbosch tbosch added the area: core Issues related to the framework runtime label Oct 4, 2016
@vicb vicb added feature Issue that requests a new feature freq1: low labels Oct 6, 2016
@ngbot ngbot bot added this to the Backlog milestone Jan 23, 2018
@jessicajaniuk
Copy link
Contributor

Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular version.

If the problem still exists in your application, please open a new issue and follow the instructions in the issue template.

@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 Apr 1, 2022
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: NgModule feature Issue that requests a new feature freq1: low
Projects
None yet
Development

No branches or pull requests

6 participants