I'm using Ionic 3 with based on angular 4 framework. And I need to know if I have multiple children components can I load them asynchronously, one by one:
- Load parent;
- Load first child;
- When first child loaded, load second child;
- When second child loaded, load third child
- and so on
For example I have a parent component app.module.ts
with children:
@NgModule({
declarations: [
AppComponentPage
],
imports: [
IonicPageModule.forChild(AppComponentPage),
ChildOneComponentModule,
ChildTwoComponentModule,
ChildThreeComponentModule,
ChildFourComponentModule,
],
entryComponents: [
AppComponentPage
]})
export class AppComponentPageModule {}
and app.component.ts
:
import { Component } from '@angular/core';
//import all child components
@Component({
selector: 'app-parent-component',
template: `
<child1-component></child1-component>
<child2-component></child2-component>
<child3-component></child3-component>
<child4-component></child4-component>
`
})
export class AppComponentPage {
//HOW TO LOAD?
}
Perhaps you mean something like:
If you want to add different components, you can use an approach like Angular 2 dynamic tabs with user-click chosen components
In each of your child components, add an output:
and emit an event when you decide that the component is initialized (or loaded, as your question says), and that the next one can thus be displayed:
In the parent component, have a counter:
Increment the counter every time a component is initialized, and don't display a component until the counter is allowing it to be displayed: