0

I have a question I just can't seem to figure out in testing and research online.

I have an Ionic Angular App I am developing. I lazy load the pages and popovers, but I noticed lazy load triggers both ngOnInit() and ionViewDidEnter() of my tabs and pages. However, I really didn't want ionViewDidEnter running unless the user actually selected those pages. I also did not want ngOnInit() to run until my app component has finished some async functions like logging in and pulling data from native storage.

So is there a way I can preserve lazy loading but hold off initializations until I am ready in the app component?

I think for the ionViewDidEnter() method I can simply use a boolean value saved in a service so I will only run content in the ionViewDidEnter with a simple "if" statement.

ionViewDidEnter(){
    if(this.myService.finshedAppInit){
        // Do stuff
    }
}

lazyload in app routing module as such

{
    path: 'tabs',
    loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule)
},

Any thoughts? Is there a particular standard to follow with loading up an app but waiting until particular async methods are complete before anything past the splash screen and app component are loaded?

I tried removing lazy loading, but this made its own issues.

1 Answer 1

0

Actually I just decided not to lazy load the tabs page, and just navigate there one the app component is done, or it goes to the login screen. This is actually pretty helpful because now nothing downstream of tabs will run unless directed there.

  {
    path: 'tabs',
    component: TabsPageModule
  },

I still do have ionViewDidEnter running downstream on pages where the viewer has not clicked on but I can manage

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.