When injecting a token in a state class an "Invalid provider" error is thrown when using an InjectionToken. Things work fine however when using a string.
To reproduce the error go to src/app.config.ts and change the CUSTOMER_CONFIG definition to the InjectionToken variant (just remove the single quotes). Next go to src/zoo.state.ts and change the constructor dependency injection to again use the InjectionToken variant (again remove the single quotes).
Error: Invalid provider
at throwInvalidProviderError (chunk-BMPG3X4X.js?v=31c34689:5199:11)
at providerToFactory (chunk-BMPG3X4X.js?v=31c34689:6599:9)
at providerToRecord (chunk-BMPG3X4X.js?v=31c34689:6577:21)
at R3Injector.processProvider (chunk-BMPG3X4X.js?v=31c34689:6473:20)
at chunk-BMPG3X4X.js?v=31c34689:6318:57
at forEachSingleProvider (chunk-BMPG3X4X.js?v=31c34689:6633:7)
at forEachSingleProvider (chunk-BMPG3X4X.js?v=31c34689:6631:7)
at new R3Injector (chunk-BMPG3X4X.js?v=31c34689:6318:5)
at new EnvironmentNgModuleRefAdapter (chunk-BMPG3X4X.js?v=31c34689:15960:22)
at internalCreateApplication (chunk-BMPG3X4X.js?v=31c34689:25536:21)
Affected Package
@ngxs/store
Is this a regression?
Unsure
Description
When injecting a token in a state class an "Invalid provider" error is thrown when using an InjectionToken. Things work fine however when using a string.
e.g.
This does work:
This does NOT work:
🔬 Minimal Reproduction
You can find a Stackblitz example demonstrating the problem here.
To reproduce the error go to
src/app.config.ts
and change theCUSTOMER_CONFIG
definition to the InjectionToken variant (just remove the single quotes). Next go tosrc/zoo.state.ts
and change the constructor dependency injection to again use the InjectionToken variant (again remove the single quotes).On top of that please find the original Stackoverflow question about this here.
🔥 Exception or Error
Environment