gpt4 book ai didi

angular - Spartacus - 从自定义 CMS 组件中检索数据

转载 作者:行者123 更新时间:2023-12-05 05:04:34 25 4
gpt4 key购买 nike

在 SAP Commerce 中,我准备了自定义 CMS 组件。我把它放在正确的插槽中。 Spartacus 收到有关它的信息 - 我可以看到该组件在页面上的正确位置。但是我怎样才能从这个组件中检索一些数据。作为对给定插槽的响应,它看起来像:

 "components": {
"component": [
{
"uid": "NewsletterComponent",
"uuid": "eyJpdGVtSWQiOiJOZXdzbGV0dGVyQ29tcG9uZW50IiwiY2F0YWxvZ0lkIjoiZWxlY3Ryb25pY3Mtc3BhQ29udGVudENhdGFsb2ciLCJjYXRhbG9nVmVyc2lvbiI6Ik9ubGluZSJ9",
"typeCode": "NewsletterComponent",
"modifiedTime": "2020-04-02T21:57:10.236+02:00",
"name": "Newsletter Component",
"container": "false",
"mailPlaceholder": "Your email address",
"mailHeaderText": "E-mail Newsletter"
}

如何从 Angular 检索这些数据?我创建了一些组件,但它不起作用

import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
import { CmsComponentData } from '@spartacus/storefront';
import { CmsComponent, CmsService } from '@spartacus/core'
import { Observable } from 'rxjs';

@Component({
selector: 'app-newsletter',
templateUrl: './newsletter.component.html',
styleUrls: ['./newsletter.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class NewsletterComponent extends CmsComponentData<CmsComponent> {

component: Observable<any>;

constructor(cmsService: CmsService) {
super();
this.component = cmsService.getComponentData('NewsletterComponent')
}


public getText(): any {
console.log(this.component)
}
}

我在模块中注册了它

B2cStorefrontModule.withConfig({
cmsComponents: {
NewsletterComponent: {
component: NewsletterComponent
}
},

我可以从服务器响应中检索 mailPlaceholder 和 mailHeader 文本吗?

最佳答案

您的组件需要在构造函数中接受组件数据,例如:https://sap.github.io/spartacus/components/ParagraphComponent.html#source

关于angular - Spartacus - 从自定义 CMS 组件中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61012608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com