4

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?

Community
  • 1
  • 1
Rosen Dimov
  • 1,055
  • 12
  • 32
  • have a static variable in a global service and use it across application. if you can create a working example will help you to solve this. – Aravind May 12 '17 at 21:06
  • by global service you mean an object which will be a property of window? – Rosen Dimov May 13 '17 at 12:26

1 Answers1

2

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

Sander Elias
  • 754
  • 6
  • 9
  • 1
    So looks like we need to use native JS techniques to solve this problem as opposed to the $rootScope and $broadcast options in AngularJS 1? – Rosen Dimov May 13 '17 at 12:29
  • 1
    Yes. indeed. $rootScope and $broadcast did only work within a single app. Loading multiple apps was kind of a challenge in AngularJS. AFAIK there is no way to share a single angular service between 2 (or more) apps. – Sander Elias May 13 '17 at 15:14