I prepared an Angular Module Federation application based on a plugin-based workflow where the remote module is loaded using the LoadRemoteModule
function.
In the remote application I have injection tokens that I would like to provide to the shell application and use them in the root appmodule - is it possible ?
So far, I managed to pass them in the served module (by providers array), but they are visible only in this module, and I would like to have them in the root scope of my whole app.
This solution didn't work when I had provideIn: root
enabled on my services, I had to add all the services that used inject tokens to the providers table of the main remote module. I am afraid that this is not a good solution. That's why I would like to use these tokens in root and not declare providers.
there is no "synchronious" apis in module federations to import something from remote, so you just won't be able to construct simple ngModule with some token from remote.
However you can do something simillar as many applications are using when loading environment during app initialization - create some ConfigService that exists initially, and then it could load something from remote in APP_INITIALIZER to store some data there.
To make api more safe it would be a good solution to put such logic into a separate "shared" npm module and used as something shared across shell and remotes. It would be easy to setup module federation so exported items from "shared" (tokens, classes, etc.) would be the same in all places.