Chrome extension with Angular - Singleton service

Viewed 21

I'm currently writing a chrome extension using angular, and I am using the popup for the user to communicate, and the popup is my angular app. I have two components, a HomeComponent and a LoginComponent, which switch with a router outlet in the main app.

As I want to communicate with a server, I generated a service to do the http requests, and store tokens / urls / etc. In each constructor of the component I added the service:

constructor HomeComponent(private service: Service){}

same for LoginComponent. My service has the @Injectable({providedIn: 'root'}) tag. But after setting a variable in the LoginComponent and switching to HomeComponent, I see that the value is not set. In fact, the constructor of the service is called again.

I think it could be an issue with the fact that it's ran by an extension, so maybe I have to add something in the webpackconfig, or maybe I just can't use services here and I am forced to communicate with background js chrome file.

0 Answers
Related