question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: Add a new lifecycle hook that runs once after ngOnInit

See original GitHub issue

New 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:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
oleg-semyonovcommented, Oct 24, 2019

@liamdebeasi OK, sure!

0reactions
ionitron-bot[bot]commented, Nov 23, 2019

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found