I have a simple @NgModule the boostrap 2 components :
// Global module for all Angular Component
@NgModule({
declarations: Components, // directives, components, and pipes owned by this NgModule
imports: [BrowserModule, HttpModule, FormsModule],
providers: Providers,
bootstrap: [Menu, Main]
})
export class MenuModule { }
I want to store a reference of my Main component bootstraped by my MenuModule. I tried to implement the .then method of bootstrapModuleDynamic(), but I only get the factory of the component.
// Bootstrap of module
platformBrowserDynamic()
.bootstrapModule(MenuModule)
.then((menuModule: NgModuleRef<MenuModule>) => {
var test: ComponentFactory<Main> = (<any>menuModule).bootstrapFactories[0];
});
Any ideas ?
I see two ways to get list of bootstraped components:
1) Using ApplicationRef
platformBrowserDynamic()
.bootstrapModule(MenuModule)
.then((menuModule: NgModuleRef<MenuModule>) => {
const appRef = menuModule.injector.get(ApplicationRef);
const components = appRef.components;
});
2) Using ngDoBootstrap method on your module:
@NgModule({
declarations: [Components, // directives, components, and pipes owned by this NgModule
imports: [BrowserModule, HttpModule, FormsModule],
providers: Providers,
entryComponents: [Menu, Main]
// bootstrap: [Menu, Main]
})
export class MenuModule {
ngDoBootstrap(appRef: ApplicationRef) {
const compRefMenu = appRef.bootstrap(Menu);
const compRefMain = appRef.bootstrap(Main);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With