小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

SAP Spartacus Popover Directive 構(gòu)造函數(shù)的用途分析

 汪子熙 2021-05-03

該構(gòu)造函數(shù)位于文件 popover.directive.ts 里:

第 11 行 cxPopOver Directive 施加到 button 元素上之后,運行時,cxPopOver Directive 的構(gòu)造函數(shù)觸發(fā)。其參數(shù),既有應(yīng)用程序定義的類型,比如 PositioningService, 也有框架使用的類型,比如 ElementRef,ViewContainerRef 等等。

  • element: 該 Directive 綁定的頁面元素,在這個例子里是 button.

  • viewContainer: 類型為 ViewContainerRef. 三個全是私有屬性。

我們注入這個實例的唯一目的,就是調(diào)用其 createComponent 方法。

const containerFactory = this.componentFactoryResolver.resolveComponentFactory(
      PopoverComponent
    );
    this.popoverContainer = this.viewContainer.createComponent(
      containerFactory
    );

createComponent 方法需要輸入?yún)?shù)為 containerFactory,后者通過另一個注入?yún)?shù)實例 componentFactoryResolver 提供。componentFactoryResolver 可以理解成制造工廠的工廠函數(shù):需要的輸入?yún)?shù)是待生產(chǎn) Component 的定義,在這個例子里為 PopoverComponent:

而 createComponent 返回的數(shù)據(jù),類型為 ComponentRef, 包含了 PopoverComponent 的實例。

  • renderer: Renderer2

引入該屬性,是為了調(diào)用其 appendChild 方法,把創(chuàng)建好的 PopoverComponent 實例,添加到 DOM 樹中去。

  • changeDetectorRef: ChangeDetectorRef

在 SAP Spartacus 實現(xiàn)中沒有用到。

  • positioningService: PositioningService

在 SAP Spartacus 實現(xiàn)中沒有用到。

負責(zé)元素 focus 相關(guān)的實現(xiàn)。

  • winRef: WindowRef

負責(zé)將新建的 PopoverComponent 實例中的 DOM 元素,添加到當(dāng)前 document 的 body 節(jié)點上。

    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章