0

I've 3 different libraries in 3 modules in my angular project: two separate libraries which include the same third library for some shared functionality. This third library has some configuration.

Assuming each module has a service ServiceA, ServiceB and ServiceZ whith a function

ServiceA.name(){return ServiceZ.name};
ServiceB.name(){return ServiceZ.name};
ServiceZ.name(){return config.foo};

Now if I call ServiceA1.name() the result shuld be A1 and ServiceA2.name() should result in A2.

How can I achieve this behaviour in angular?

Demo

Verim
  • 1,065
  • 9
  • 17
  • 1
    Your demo code seems to be almost there no? The only thing that probably needs to be done is to remove the providedIn: root for the service you’d like to configure. Instead, provide the service in both A modules (this way, they get their own instance) – MikeOne May 30 '22 at 16:16
  • That's what I assumed as well. Any idea what specific I have to change? I tried already `providedIn: 'any'` / `root`/ `platform`/`BModule` – Verim May 30 '22 at 16:35
  • Completely remove that object in the service itself and add the service in the providers arrays in the modules itself – MikeOne May 30 '22 at 16:57
  • Sadly it's the same result – Verim May 30 '22 at 18:25

0 Answers0