SAP Spartacus NullInjectorError: No provider for CmsComponentData - spartacus-storefront

I am trying to get the component data of a custom component.
private componentData$: Observable<CmsBannerCarouselComponent> = this.componentData.data$.pipe(
filter(Boolean),
tap((d: CmsBannerCarouselComponent) => (console.log("++++++++++++++++++++++++++",d)))
);
I am getting the following error:
core.js:4197 ERROR NullInjectorError: R3InjectorError(AppModule)[CmsComponentData
-> CmsComponentData -> CmsComponentData]:
NullInjectorError: No provider for CmsComponentData!
Can anyone help me to fix this?

If you use the CmsComponentData in a constructor, it must be provided. This is what Spartacus is doing when a CMS component is placed on the page; while creating the component dynamically, a data object is composed and provided in the injector of that component.
The CmsComponentData is an abstract class, so if you add a component without injecting a concrete class, you'll face this error.
We've seen this lately by a dev who wanted to assign the component to a route. This is an example where the Angular will try to fetch a concrete class from the DI system, but there's nothing in Spartacus unless you do this yourself.

I also faced this error. It happens when you try to add the custom component in app.component.html which is not required as these compoment are mapped through the ConfigModule. So remove the tag of the custom component from app.component.html and it will work.

Related

Does OutletService support dynamically adding component in button handler

i used this.outletService.add('BottomHeaderSlot', factory, OutletPosition.BEFORE); during the search button click handler to add a custom component in the BottomHeaderSlot. I intended to add searchOverlay under the header to add customized search behavior.
But my custom component is not shown under the header after calling outletService.add. I refered to this https://sap.github.io/cloud-commerce-spartacus-storefront-docs/outlets/ . Does outletService support dynamic adding component during runtime?
Following is my button handler
open(): void {
const factory = this.componentFactoryResolver.resolveComponentFactory<SearchOverlayComponent>(SearchOverlayComponent);
this.outletService.add('BottomHeaderSlot', <any>factory, OutletPosition.BEFORE);
this.cd.markForCheck();
That's a good question. At the moment it is a not a feature supported from our outlets.
A solution you could do is inject the component in a more static manner (either CMS or outlet when the app initializes like seen here https://github.com/SAP/cloud-commerce-spartacus-storefront/blob/develop/projects/storefrontlib/src/cms-components/asm/services/asm-enabler.service.ts)?
Your component could then be wrapped with an <ng-container *ngIf="open$ | async></ng-container> where open$ is an observable for the state of the search box. That way the component only appears in the dom when the searchbox is open.
The idea of dynamically adding a components through outlets is a good one we will keep in mind. I will open an issue on Github as an improvement.

What means this Exception?

I try to test a code and got the Exception below:
The component(s) below failed to render. Possible reasons could be that: 1) you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered), 2) if your components were added in a parent container then make sure the markup for the child container includes them in .
I don't know what to do now.
This error means that you have added a component in your Java code, e.g.:
add(new Label("someId", "Some text"));
but you forgot to add wicket:id="someId" to the corresponding HTML template.
So, Wicket says: I have a component in the Java component tree that I have no idea where and how to render.

Invariant Violation: Could Not find "store" in either context of props of "Connect(App)"

Note, before reading I have already looked at the following:
JestJS -> Invariant Violation: Could not find "store" in either the context or props of "Connect(Portfolio)"
ReactJs/Redux Invariant Violation: Could not find "store" in either the context or props of "Connect(LoginContainer)"
Could not find "store" in either the context or props of "Connect(App)" In an react-redux app
Also, I followed the tutorial shown here: https://www.youtube.com/watch?v=9mlwjZL3Fmw
The major difference is that I used create-react-native-app to initialize my project where the video creator does not.
I want to know if it's possible to get the connect to recognize all the components while keeping the App component in App.js as a js const.
The previous solutions offered work when I switch to using a javascript class instead:
class App extends React.Component { etc..
The code is available here: https://github.com/qxh5696/first-react-native-app
I'd like to find the root cause as to why the "store" is not being recognized. Call it stubbornness but I am curious to know if anyone has found a solution to this problem.
The root cause of the error is when we put together a react-redux application we should expect to see a structure where at the top we have the Provider tag which has an instance of a redux store.
That Provider tag then renders your parent component, lets call it the App component which in turn renders every other component inside the application.
Here is the key part, when we wrap a component with the connect() function, that connect() function expects to see some parent component within the hierarchy that has the Provider tag.
So the instance you put the connect() function in there, it will look up the hierarchy and try to find the Provider.
Thats what you want to have happen, but in your test environment that flow is breaking down.
import
import {connect} from "react-redux";
instead of
import connect from "react-redux/es/connect/connect";

VueJS: Error in mounted Third party component

I'm trying to integrate third-party component Adaptive card in my application using VueJs but getting following error when wrapping it inside a separate component so that I can re-use it in other places.
Error in mounted hook: "TypeError: this._card.onExecuteAction is not a
function"
I've created a Demo to show the work done so far, can anyone suggest what I'm missing here.
I just need to integrate this adaptive card in my project as a reusable component
In fact, you are trying to call onExecuteAction function, instead of assigning it. It can be fixed, like this: this._card.onExecuteAction = action => this.$emit("action", action);
ps. i suggest you need also use :card="card" in your component template definition in TodoLis.vue and then add something like #action="handleAction" to it, to handle events emitted by your component.

Can we have state base routing in Aurelia

Can we have a state base routing in Aurelia JS like angular ui router
Currently I have routes like this
root/<userid>/<feature>.
Now I am just trying to implement the same in following way
root/<userid> and feature should be pass as a parameter.The problem is that
Once the component is loaded in memory it is not getting updated on params change.
TIA
You need to configure the lifecycle to be invoked any time the URL parameters change.
See "Reusing an Existing VM" at the link below.
http://aurelia.io/hub#/doc/article/aurelia/framework/latest/cheat-sheet/7
"Since the VM's navigation life-cycle is called only once you may have problems recognizing that the user switched the route from Product A to Product B (see below). To work around this issue implement the method determineActivationStrategy in your VM and return hints for the router about what you'd like to happen."
In your view model write the following method:
determineActivationStrategy {
return activationStrategy.invokeLifecycle;
}