matth3o matth3o - 3 months ago 27
Dart Question

Is it a best practice to have a top level component in Angular2?

All is in the title :)

I want to create angular2 components in an already existing application.

In every tutorial I saw, there is a top level component which is created and contains all the features.

Is it really necessary to do so, or can I have multiple components not related with each other ?

Thanks for your help

Answer

You can bootstrap more than one component.
The components need to have different selectors. You can use a shared services to communicate between these applications.

MyService myService = new MyService();

bootstrap(AppComponent1, [new Provider(MyService, useValue: myService)]);
bootstrap(AppComponent2, [new Provider(MyService, useValue: myService)]);

You should be aware that the change of one "app" that causes a callback to be called in another one, makes the callback run in the zone of the caller, not the receiver. It was mentioned to get rid of NgZone in Angular2 Dart because it's not necessary there. I don't know yet if this will change anything.