SAP Spartacus B2B Popover Directive 和 Popover Component 的生命週期管理

解析 SAP Spartacus B2B list 實現,即list.component.html時,由於在Component 模板裏遇到了[cxPopover]指令,所以觸發依賴注入:html

首先建立directive實例:函數

當點擊宿主元素 icon 時,由於@HostListener 註解的緣由,一旦宿主元素髮生了 click 事件後,咱們定義在 directive 實現裏的handleOpen方法會自動被調用:this

下圖標號爲1的componentFactoryResolver,來自Popover directive 構造函數的依賴注入;spa

標號爲2的PopoverComponent,來自咱們在另外一個文件裏實現並經過export 導出的Component:component

標號爲3的PopoverContainer,是this.viewContainer(一樣是構造函數依賴注入的結果)調用 createComponent 返回的結果,其結構爲:htm

在這裏插入圖片描述

this.popoverContainer.changeDetectorRef.detectChanges();

手動觸發PopoverComponent的Change detection - 變動檢測
事件

而後調用handlePopoverEvents,執行事件處理註冊邏輯:圖片

更多Jerry的原創文章,盡在:"汪子熙":
rem

相關文章
相關標籤/搜索