I am having the following errors when I try to override and extend the
CheckoutStepsSetGuard:ERROR Error: Uncaught (in promise): Error: Invalid CanActivate guard in cmsMapping Error: Invalid CanActivate guard in cmsMapping (...) ERROR NullInjectorError: R3InjectorError(AppModule)[CheckoutStepsSetGuard -> > MyCheckoutStepsSetGuard -> ActiveCartService -> ActiveCartService -> ActiveCartService]: NullInjectorError: No provider for ActiveCartService!Do you know what could be wrong ?
Error: No provider for ActiveCartService! - when extending CheckoutStepsSetGuard in Spartacus
95 Views Asked by Krzysztof Platis At
1
What this Angular Dependency Injection error might mean in the context of SAP Spartacus:
It looks that the
ActiveCartServicehasn't been provided yet, while it's already was attempted to be injected. I guess there is a race condition - we try to inject the service but the JS chunk with the cart functionality hasn't been lazy loaded yet (and the implementation ofActiveCartServicewasn't provided yet).I believe the remedy to such an issue is using the proxy
ActiveCartFacadeinstead (Facadeinstead ofService). TheFacadeis a safe proxy object for accessing theActiveCartServiceeven when it's implementation not lazy loaded yet. Actually, calling any method of theActiveCartFacadewill implicitly trigger for you the lazy loading of the whole JS chunk with the cart functionality in the background, including the loading and providing of the the actual implementation of theActiveCartService.For more, see the official SAP Spartacus docs for Proxy Facades.