When I use lazy loading modules from Spartacus with service providers I get an error about the need to provide services: app.module.ts:
ConfigModule.withConfig({
featureModules: {
customCheckoutComponentModule: {
module: () => import('@checkout/checkout.module').then((m) => m.CustomCheckoutComponentModule),
cmsComponents: [
'CheckoutOrderSummary',
'CheckoutShippingDate'
],
},
},
})
Lazy module:
@NgModule({
imports: [
CommonModule,
CheckoutOrderSummaryModule,
...
],
providers: [
{
provide: CustomCheckoutDeliveryAdapter,
useClass: CustomOccCheckoutDeliveryAdapter,
},
{
provide: CheckoutAdapter,
useClass: CustomOccCheckoutAdapter,
},
{
provide: PageMetaResolver,
useExisting: CustomCheckoutPageMetaResolver,
multi: true,
},
],
})
export class CustomCheckoutComponentModule {}
When I try to navigate to this lazy module, I get the following error: Error providers
errorhandler.js:33 Error: Uncaught (in promise): NullInjectorError: R3InjectorError(CustomCheckoutComponentModule)[EffectsFeatureModule -> InjectionToken ngrx/effects: Feature Effects -> [object Object] -> PolygonsEffects -> CustomCheckoutDeliveryConnector -> CustomCheckoutDeliveryConnector -> CustomCheckoutDeliveryAdapter -> CustomCheckoutDeliveryAdapter -> CustomCheckoutDeliveryAdapter]:
NullInjectorError: No provider for CustomCheckoutDeliveryAdapter!
NullInjectorError: R3InjectorError(CustomCheckoutComponentModule)[EffectsFeatureModule -> InjectionToken ngrx/effects: Feature Effects -> [object Object] -> PolygonsEffects -> CustomCheckoutDeliveryConnector -> CustomCheckoutDeliveryConnector -> CustomCheckoutDeliveryAdapter -> CustomCheckoutDeliveryAdapter -> CustomCheckoutDeliveryAdapter]:
NullInjectorError: No provider for CustomCheckoutDeliveryAdapter!
This error occurs in only lazy module where providers exist
Lazy modules without providers do normal loading
I tried to move providers out of the lazy module, but failed
This is a late answer but perhaps it will be somewhat useful to somebody,
Have been experiencing a similar issues with mat-dialog and mat-select and after trying out everything, i decided to go for standalone components (Angular 14+) and it is been working great.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.