What I want to achieve
An encapsulated application (form editor) that I can use inside another angular application, but also in any web application.
Idea
The main modules/components could be implemented as angular library (main component as shadow dom), so I can add an 'angular elements' wrapper to build the webcomponent, but can also import the library itself as a npm package inside my existing angular application. So my angular application would not load the complete javascript package, but just the modules, that are not provided but the other application, to get a better performance and integration.
Problem
For each requests from the library, I want an http interceptor to login / add the jwt token to the request header. When I build the application with the angular elements wrapper (doing nothing but importing the library and building the webcomponent), everything is working fine. When I add it to the angular application, the interceptor is not working as expected, because the other application also has an interceptor. I want to encapsulate the libraries interceptor to the library only. So I thought I just have to import the HttpClientModule inside my library again and get my own instance of it, so the defined HTTP_INTERCEPTORS provider inside the same file knows when to get triggered. Unfortunatelly this idea is not working and both are interfering.
AppModule
- imports:
- HttpClientModule(1)
- CustomLibraryModule
- providers:
- HTTP_INTERCEPTORS(1)
CustomLibraryModule
- imports:
- HttpClientModule(2)
- providers:
- HTTP_INTERCEPTORS(2)
In best case, I want to import CustomLibraryModule inside a lazy loaded child module of my application.
Question
Am I choosing the right tools for this situation? Do you know what I am doing wrong to get my encapsulated http interceptor?