You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have an Angular app that we are converting to standalone. After some trial and error everything went fine, except for a single case.
We have a component that asks the user for some data confirmation. This happens usually every two years. Clearly we want to load this component only when needed.
The component itself is loaded inside a dialog, but it has some state and some effects. Now, to provide state and effects I need an EnvironmentInjector (as ProvideEffects returns an EnvironmentProvider).
I can't use providers array in bootstrapApplication as it is global, and I haven't a route, as the component is loaded inside a dialog, no matter what is the page selected.
the angular guide (https://angular.io/guide/standalone-components#environment-injectors) says
So I think the only option left is to create an EnvironmentInjector with CreateEnvironmentInjector. This, from what I have understood, would imply injecting an ApplicationRef to get the root injector and pass it as parent to CreateEnvironmentInjector.
I don't know if this is possible with provideEffects, or if there is a canonical way to do this, or simply a better way.
Could someone point me in the right direction?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We have an Angular app that we are converting to standalone. After some trial and error everything went fine, except for a single case.
We have a component that asks the user for some data confirmation. This happens usually every two years. Clearly we want to load this component only when needed.
The component itself is loaded inside a dialog, but it has some state and some effects. Now, to provide state and effects I need an EnvironmentInjector (as ProvideEffects returns an EnvironmentProvider).
I can't use providers array in bootstrapApplication as it is global, and I haven't a route, as the component is loaded inside a dialog, no matter what is the page selected.
the angular guide (https://angular.io/guide/standalone-components#environment-injectors) says
So I think the only option left is to create an EnvironmentInjector with CreateEnvironmentInjector. This, from what I have understood, would imply injecting an ApplicationRef to get the root injector and pass it as parent to CreateEnvironmentInjector.
I don't know if this is possible with provideEffects, or if there is a canonical way to do this, or simply a better way.
Could someone point me in the right direction?
Beta Was this translation helpful? Give feedback.
All reactions