Render Angular component outside the main app

前端 未结 2 1435
挽巷
挽巷 2020-12-19 04:20

I have an angular app, it has a bundle and a piece of HTML that contains a root selector

 

where the app is bootstr

相关标签:
2条回答
  • 2020-12-19 05:04

    Just add any components you need to the bootstrap array that is passed to NgModule:

    @NgModule({
      declarations: [AppComponent, ContactFormComponent],
      imports: [...],
      providers: [SharedService],
      bootstrap: [AppComponent, ContactFormComponent]
    })
    export class AppModule {}
    

    and now voila this works:

    <html><body>
      <app-contact-form></app-contact-form>
      ============================================
      <app-root></app-root>
    </body></html>
    

    Just learned this from the plunker in the answer Günter linked above. very cool. tested with angular 6

    0 讨论(0)
  • 2020-12-19 05:08

    You can bootstrap multiple elements. You can inject a shared service to be able to communicate between components of different Angular2 applications (on the same page).

    How to dynamically create bootstrap modals as Angular2 components?

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