I have a set of custom components which is created in CMS. The custom components extend the BannerComponent and have it's own property called "color".
I have created the model:
import { BannerComponent } from '@spartacus/storefront';
export class TestComponent extends BannerComponent{
color?: string;
}
And I am trying to get the data from the Angular component.
constructor(private componentData: CmsComponentData, private cmsService: CmsService) { }
While doing this I am getting the following error:
Type 'TestComponent' has no properties in common with type 'CmsComponent'.
How to resolve this and get data of custom component in the angular component.
The error you're getting is coming from the typescript compiler. During that check, there's no information available to understand that you're actually expecting a
BannerComponent
interface. Remember, typescript is doing static code validation.To make the compiler aware of the expected interface, you need to tell it. By default, the
CmsComponentData
class uses theCmsComponent
interface. You can however pass in a custom interface, by passing the interface to theCmsComponentData
: