You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Composable Storefront中用LaunchDialogService替换ModalRef

Composable Storefront 5.0 模态框API迁移指南
  • 已移除API:ModalService、ModalDirective、ModalDirectiveOptions、ModalDirectiveService、ModalOptions、ModalRef
  • 替代方案:使用从@spartacus/storefront导入的LaunchDialogService

原基于ModalService的实现代码

this.modalRef = this.modalService.openModal(CalculateModalComponent, {
  centered: true,
  size: 'lg',
  scrollable: true,
  windowClass: 'finance-calculator-modal',
  ariaLabelledBy: AccessibilityConstants.MODAL_TITLE_ID,
});
modalInstance = this.modalRef.componentInstance;
modalInstance.productCode = this.wishlistProduct.code;

迁移为LaunchDialogService的实现代码

// 导入所需依赖
import { LaunchDialogService } from '@spartacus/storefront';
import { ComponentRef } from '@angular/core';

// 在组件构造函数中注入LaunchDialogService
constructor(private launchDialogService: LaunchDialogService) {}

// 替换原模态框打开逻辑
const dialogRef: ComponentRef<CalculateModalComponent> = this.launchDialogService.openDialog(
  CalculateModalComponent,
  {
    centered: true,
    size: 'lg',
    scrollable: true,
    windowClass: 'finance-calculator-modal',
    ariaLabelledBy: AccessibilityConstants.MODAL_TITLE_ID,
  }
);
const modalInstance = dialogRef.instance;
modalInstance.productCode = this.wishlistProduct.code;

迁移说明

  • LaunchDialogService.openDialog()方法返回ComponentRef对象,替代原ModalRef的功能
  • 组件实例通过dialogRef.instance获取,替代原modalRef.componentInstance
  • 原模态框配置参数可直接复用,格式与LaunchDialogService的配置兼容

内容的提问来源于stack exchange,提问作者Miraj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 04:15:19