feat: Add a new lifecycle hook that runs once after ngOnInit
See original GitHub issueNew Lifecycle Hook for Ionic Angular
Ionic version: [x] 4.x
I feel that it would be nice to include a new ionic lifecycle hook that runs only one time after the view enters or right after ngOnInit.
Currently, when calling Http services from ngOnInit it blocks the navigation button on the previous page from transitioning and can confuse the user as to whether the button has received their click or not.
Possible solution
It would be nice to have the life cycle hooks go like
ngOnInit() -> ionFirstViewEnter() -> ionViewWillEnter() -> ionViewDidEnter() -> ...
Current solution I am using
Right now to get around ngOnInit from blocking I have used this code
public userItemList: IUserItem[];
private initialResultsShown = false;
/**
* Show recommended users
*/
public ionViewDidEnter() {
if (!this.initialResultsShown) {
this.http.searchUsers('').toPromise().then((res) => {
this.userItemList = res;
this.initialResultsShown = true;
}).catch(err => console.log(err));
}
}
What I would like
public userItemList: IUserItem[];
/**
* Show recommended users
*/
public ionFirstViewEnter() {
this.http.searchUsers('').toPromise().then((res) => {
this.userItemList = res;
this.initialResultsShown = true;
}).catch(err => console.log(err));
}
Cheeeeeers
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Lifecycle hooks - Angular
Your application can use lifecycle hook methods to tap into key events in the lifecycle of a component or directive to initialize new...
Read more >Angular Lifecycle Hooks: ngOnChanges, ngOnInit, and more
This article presents the lifecycle hooks in order of their execution (if they all execute). Certain conditions merit a hook's activation. There ...
Read more >Is there a lifecycle hook that runs once after a components ...
View queries are set before the ngAfterViewInit callback is called. and it comes after OnChanges hook, where; OnChanges is called when any data ......
Read more >Complete Guide: Angular lifecycle hooks
In this article, we will take a deeper dive into each lifecycle hook and look at how ... Then run the following commands...
Read more >Angular Lifecycle Hooks
ngOnInit 3. ngDoCheck 4 ... ngOnChanges ○ Purpose: ○ Respond when Angular (re)sets data-bound input ... ngOnInit ○ Purpose: ○ Respond when Angular...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@liamdebeasi OK, sure!
Thanks for the issue! This issue is being closed due to the lack of a reply. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Thank you for using Ionic!