Rokata
Rokata

Reputation: 1229

Communication between two Angular 4 apps

I saw answers here and here regarding this topic, but they're for version 2 beta (as far as I know we should bootstrap a module, not a component now; also I didn't find bootstrap function in the docs for version 4).

I also read an article which points to an interesting comment in the source on GitHub. The most interesting part is

For this reason, Angular creates exactly one global platform object which stores all shared services, and each angular application injector has the platform injector as its parent.

Finnally, my questions are: What is the best pattern for inter-apps communication on the same browser page? How can we ensure some order of bootstrap for the different apps?

Upvotes: 4

Views: 4719

Answers (1)

Sander Elias
Sander Elias

Reputation: 754

There are multiple solutions for this. The simplest being (as stated in a comment) include a global in the page, and use some getters and setters that fire off events, so the other apps know something has changed. If you are comfortable with observables, you can use those for that.

If you are going down this path, you might want to take a look at localStorage, wich does mostly the same as the above solution but also enables you to do this between different tabs/windows. Also, it allows you to retain some stuff between session. (if you don't want/need that uses sessionStroage instead

Upvotes: 2

Related Questions