SAP Spartacus Popover Directive 构造函数的用途分析
該構(gòu)造函數(shù)位于文件 popover.directive.ts 里:
第 11 行 cxPopOver Directive 施加到 button 元素上之后,運(yùn)行時(shí),cxPopOver Directive 的構(gòu)造函數(shù)觸發(fā)。其參數(shù),既有應(yīng)用程序定義的類型,比如 PositioningService, 也有框架使用的類型,比如 ElementRef,ViewContainerRef 等等。
- element: 該 Directive 綁定的頁(yè)面元素,在這個(gè)例子里是 button.
- viewContainer: 類型為 ViewContainerRef. 三個(gè)全是私有屬性。
我們注入這個(gè)實(shí)例的唯一目的,就是調(diào)用其 createComponent 方法。
const containerFactory = this.componentFactoryResolver.resolveComponentFactory(PopoverComponent);this.popoverContainer = this.viewContainer.createComponent(containerFactory);createComponent 方法需要輸入?yún)?shù)為 containerFactory,后者通過(guò)另一個(gè)注入?yún)?shù)實(shí)例 componentFactoryResolver 提供。componentFactoryResolver 可以理解成制造工廠的工廠函數(shù):需要的輸入?yún)?shù)是待生產(chǎn) Component 的定義,在這個(gè)例子里為 PopoverComponent:
而 createComponent 返回的數(shù)據(jù),類型為 ComponentRef, 包含了 PopoverComponent 的實(shí)例。
- renderer: Renderer2
引入該屬性,是為了調(diào)用其 appendChild 方法,把創(chuàng)建好的 PopoverComponent 實(shí)例,添加到 DOM 樹中去。
之所以不直接操作原生 DOM,是為了跨平臺(tái)支持。
- changeDetectorRef: ChangeDetectorRef
在 SAP Spartacus 實(shí)現(xiàn)中沒有用到。
- positioningService: PositioningService
在 SAP Spartacus 實(shí)現(xiàn)中沒有用到。
負(fù)責(zé)元素 focus 相關(guān)的實(shí)現(xiàn)。
- winRef: WindowRef
負(fù)責(zé)將新建的 PopoverComponent 實(shí)例中的 DOM 元素,添加到當(dāng)前 document 的 body 節(jié)點(diǎn)上。
更多Jerry的原創(chuàng)文章,盡在:“汪子熙”:
總結(jié)
以上是生活随笔為你收集整理的SAP Spartacus Popover Directive 构造函数的用途分析的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Flash如何制作过渡卷动效果精美图库展
- 下一篇: 硬盘上的esp分区和msr分区_win1