Angular 2 bootstrap multi root component

后端 未结 2 835
臣服心动
臣服心动 2021-02-09 10:06

I would like to be able to boot multiple app root component into my index.html page. This was initially possible on angular 2 beta 0 - 15, but starting in beta 16, it is not wor

相关标签:
2条回答
  • 2021-02-09 10:20

    Just list all the components in bootstrap (and declarations)

    @NgModule({
      imports: [ BrowserModule ],
      declarations: [ App, ModalComponent, CompComponent],
      providers: [SharedService],
      entryComponents: [CompComponent],
      bootstrap: [ App, ModalComponent ]
    })
    export class AppModule{}
    

    See also How to dynamically create bootstrap modals as Angular2 components? for a full example.

    0 讨论(0)
  • 2021-02-09 10:25

    http://plnkr.co/edit/APFwcpOGsMlOMVdGCkCI

    It got much easier with newer versions:

    bootstrap(Comp1);
    bootstrap(Comp2);
    

    Also here is a more advanced example of how to implement communication between applications: http://plnkr.co/edit/aZqdJe3OZ8K2odHioWkB

    0 讨论(0)
提交回复
热议问题