StackOverflow问题:How to share CMSComponentData between several components in Spartacus manner
問題:https://stackoverflow.com/questions/65815289/how-to-share-cmscomponentdata-between-several-components-in-spartacus-manner/65820581#65820581
Let’s imagine that we have CMS Component:
ConfigModule.withConfig(<CmsConfig>{cmsComponents: {CMSSupportComponent: {component: SupportButtonComponent,},}, }),But from inside we have to open another Angular component which also needs the same CMSComponentData. Simple Angular component relates to the same Angular module.
I know that we can do it via Angular Service, common for Angular manner (this requires some handy work). But maybe Spartacus has some approaches similar to:
ConfigModule.withConfig({cmsComponents: {SearchBoxComponent: {providers: [{provide: SearchBoxComponentService,useClass: CustomSearchBoxComponentService,deps: [CmsComponentData, ProductSearchService, RoutingService]}];}} });and we can share injected CmsComponentData via single Service for several components.
解答
as defined in Spartacus documentation:
The CMS data that is related to a component is provided to the component by the CmsComponentData service during instantiation. The CmsComponentData service contains the component uid, and also data$, which is an observable to the component payload. By making use of the Angular dependency injection (DI) system, components and component-specific services can use the CmsComponentData.
it’s recommended way to use Angular DI to inject CmsComponentData service and used in your components.
總結
以上是生活随笔為你收集整理的StackOverflow问题:How to share CMSComponentData between several components in Spartacus manner的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 最强蜗牛兰奢待怎么得 贵重物品图鉴大全
- 下一篇: 将1password账户的资料拷贝到另个