关于sap:SAP-Spartacus-B2B-Popover-Directive-和-Popover-Component-的生命周期管理

2次阅读

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

解析 SAP Spartacus B2B list 实现,即 list.component.html 时,因为在 Component 模板里遇到了 [cxPopover] 指令,因而触发依赖注入:

首先创立 directive 实例:

当点击宿主元素 icon 时,因为 @HostListener 注解的起因,一旦宿主元素产生了 click 事件后,咱们定义在 directive 实现里的 handleOpen 办法会主动被调用:

下图标号为 1 的 componentFactoryResolver,来自 Popover directive 构造函数的依赖注入;

标号为 2 的 PopoverComponent,来自咱们在另一个文件里实现并通过 export 导出的 Component:

标号为 3 的 PopoverContainer,是 this.viewContainer(同样是构造函数依赖注入的后果)调用 createComponent 返回的后果,其构造为:

this.popoverContainer.changeDetectorRef.detectChanges();

手动触发 PopoverComponent 的 Change detection – 变更检测

而后调用 handlePopoverEvents,执行事件处理注册逻辑:

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

正文完
 0