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 working anymore. Please refer to this code http://plnkr.co/edit/A7fyFUST9IdP1FriauXk?p=preview
please see plunker link above for the code
Hope somebody can modify the code to be able to work on angular 2 beta 17.
Thanks in advance.
You can manually bootstrap your app by using angular. bootstrap() function, for multiple modules.
In such scenarios, an Angular Element or web component should be isolated, fulfil a single functionality and communicate with the outside world using inputs & outputs. You can however also compile multiple Angular Elements out of a single Angular app, use them separately inside some index.
The bootstrap arraylink Inserting a bootstrapped component usually triggers a cascade of component creations that fill out that tree. While you can put more than one component tree on a host web page, most applications have only one component tree and bootstrap a single root component.
The bootstrap property or key of the NgModule decorator specifies which component should be loaded by Angular when the app-level module loads. Angular reads the bootstrap metadata and loads the app-level component, called AppComponent .
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With