loading two components in angular2 non SPA

后端 未结 2 1700
你的背包
你的背包 2021-01-23 13:19

Given the following components. I want to use these components on a non SPA web site exactly like the plunker here. This sample is no longer valid, as the latest beta of angular

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-23 13:27

    The answer to anyone else attempting this, is to create two modules, and register each module separately

    Registration

    //main entry point
    import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
    import {AppModuleA, AppModuleB} from './app';
    
    platformBrowserDynamic().bootstrapModule(AppModuleA);
    platformBrowserDynamic().bootstrapModule(AppModuleB);
    

    Modules

    @NgModule({
      imports: [ BrowserModule ],
      declarations: [ AppA ],
      bootstrap: [ AppA ]
    })
    export class AppModuleA {}
    
    @NgModule({
      imports: [ BrowserModule ],
      declarations: [ AppB ],
      bootstrap: [ AppB ]
    })
    export class AppModuleB {}
    

提交回复
热议问题