【问题标题】:Angular 2 bootstrap multi root componentAngular 2 引导多根组件
【发布时间】:2016-05-06 07:12:18
【问题描述】:

我希望能够将多个应用程序根组件引导到我的 index.html 页面中。这最初在 angular 2 beta 0 - 15 上是可能的,但从 beta 16 开始,它不再工作了。请参考此代码 http://plnkr.co/edit/A7fyFUST9IdP1FriauXk?p=preview

please see plunker link above for the code

希望有人可以修改代码以便能够在 Angular 2 beta 17 上工作。

提前致谢。

【问题讨论】:

    标签: angular


    【解决方案1】:

    只需列出bootstrap(和declarations)中的所有组件

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

    有关完整示例,另请参阅 How to dynamically create bootstrap modals as Angular2 components?

    【讨论】:

      【解决方案2】:

      http://plnkr.co/edit/APFwcpOGsMlOMVdGCkCI

      使用新版本会更容易:

      bootstrap(Comp1);
      bootstrap(Comp2);
      

      这里还有一个更高级的示例,说明如何实现应用程序之间的通信: http://plnkr.co/edit/aZqdJe3OZ8K2odHioWkB

      【讨论】:

        猜你喜欢
        • 2019-03-16
        • 2016-06-14
        • 1970-01-01
        • 2017-06-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-17
        • 2016-07-27
        相关资源
        最近更新 更多