Angular 获取引导组件
我有一个简单的Angular 获取引导组件,angular,typescript,Angular,Typescript,我有一个简单的@NgModuleboostrap 2组件: // Global module for all Angular Component @NgModule({ declarations: Components, // directives, components, and pipes owned by this NgModule imports: [BrowserModule, HttpModule, FormsModule], providers: Provi
@NgModule
boostrap 2组件:
// 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 { }
我想存储由我的MenuModule
引导的Main
组件的引用。我尝试实现。然后bootstrapModuleDynamic()
方法,但我只得到组件的工厂
// Bootstrap of module
platformBrowserDynamic()
.bootstrapModule(MenuModule)
.then((menuModule: NgModuleRef<MenuModule>) => {
var test: ComponentFactory<Main> = (<any>menuModule).bootstrapFactories[0];
});
//模块的引导
platformBrowserDynamic()
.bootstrapModule(菜单模块)
.然后((菜单模块:NgModuleRef)=>{
var测试:ComponentFactory=(menuModule).bootstrapFactories[0];
});
有什么想法吗?我看到了两种获取引导组件列表的方法:
1) 使用ApplicationRef
platformBrowserDynamic()
.bootstrapModule(MenuModule)
.then((menuModule: NgModuleRef<MenuModule>) => {
const appRef = menuModule.injector.get(ApplicationRef);
const components = appRef.components;
});
谢谢我选择第一个解决方案。如何在main.ts中加载NgModuleRef和ApplicationRef@ChristopheGigax@ChristopheGigax,你能和我分享一下加载上述程序的代码吗?对不起,我已经没有代码了。那是很久以前的事了。也许您可以使用bootstrapModule
方法的then
方法找到NgModuleRef
。@christophergax,谢谢您的回复。您能否以任何方式帮助您编写该文件,如main.ts或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);
}
}