Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 获取引导组件_Angular_Typescript - Fatal编程技术网

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);
   }
}