0

I'm trying to register dependencies from a feature loaded module and I can't figure out how to use these dependencies from other modules. I don't think that it's not possible at all since all the information exists on the client.

I've created a stackblitz to reproduce: Stackblitz implementation

Clicking on count shows the amount of registered dependencies of type EXCEPTION_FORMATTER. Clicking on "Orders" loads a feature module with a dependency. Clicking count again still only findes one dependency.

2 Answers 2

1

Unfortunately it's not something that can be done if you use Lazy-loading.

If you need providers as "multiple" in cascade (access parent and child providers in child module), this issue can help you. I did an update of your stackblitz here to make you an example.

If you need to access child registred providers from the parent, you will need to do it another way has mentioned here. You can use a singleton that contains an array of "callback" where you can add or remove some of them.

Sign up to request clarification or add additional context in comments.

3 Comments

I haven't found a solution for this, too. But why shouldn't this be possible? All the information required is stored on the client. But yes, singleton services is probably the way to go.
I think the main problem is that we cannot give a providedIn:"root" config when we create a provider using a token (and multi flag).
Ok, so that is the most satisfying answer for now. Opened a feature request on github: github.com/angular/angular/issues/39414
0

You can search a solution with the forRoot pattern : https://angular.io/guide/singleton-services#the-forroot-pattern

And after try to do something inspired by this :

https://github.com/ngrx/platform/blob/aa9bf1a1ed04020d1b9dba70f939de248a6238b1/modules/store/src/store_module.ts

with forRoot() forFeature() static module functions, the great Ngrx store library can increment the current store when a lazy module load a feature store module. Only after the lazy module is loaded, you can use the newly loaded store by other lazy loaded modules.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.