关于sap:SAP-电商云-Spartacus-UI-Angular-Component-动态创建的单步调试

8次阅读

共计 533 个字符,预计需要花费 2 分钟才能阅读完成。

Jerry 之前的文章 SAP 产品 UI 里的容器组件的概念和开发概述介绍过,SAP Spartacus Angular Component,通过咱们开发团队自定义的指令 cxComponentWrapper 进行渲染。

在运行时,依据 Angular Component 的名称,即第 90 行 flexType 字段蕴含的 QuickOrderComponent,咱们可能应用 Angular Component 动态创建 API 来触发这个 Component 的渲染。

default-component.handler.ts 里,调用 viewContainerRef 的 createComponent 办法,创立 Component 实例。

待创立的 Component 如果 constructor 里定义了内部依赖,须要实现这些依赖的创立和注入:

这里待注入的 token 就是 QuickOrderFacade:

这里解析出的 provider 是 QuickOrderService:

CoreModule 一旦被加载,下图第 6 行 facadeProviders 里的 provider 定义立刻失效:

也就是说,运行时,QuickOrderService 会成为 QuickOrderFacade 的具体实现:

更多 Jerry 的原创文章,尽在:” 汪子熙 ”:

正文完
 0