关于sap:SAP-Spartacus-Popover-Directive-构造函数的用途分析

该构造函数位于文件 popover.directive.ts 里:

第 11 行 cxPopOver Directive 施加到 button 元素上之后,运行时,cxPopOver Directive 的构造函数触发。其参数,既有利用程序定义的类型,比方 PositioningService, 也有框架应用的类型,比方 ElementRef,ViewContainerRef 等等。

  • element: 该 Directive 绑定的页面元素,在这个例子里是 button.

  • viewContainer: 类型为 ViewContainerRef. 三个全是公有属性。

咱们注入这个实例的惟一目标,就是调用其 createComponent 办法。

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

createComponent 办法须要输出参数为 containerFactory,后者通过另一个注入参数实例 componentFactoryResolver 提供。componentFactoryResolver 能够了解成制作工厂的工厂函数:须要的输出参数是待生产 Component 的定义,在这个例子里为 PopoverComponent:

而 createComponent 返回的数据,类型为 ComponentRef, 蕴含了 PopoverComponent 的实例。

  • renderer: Renderer2

引入该属性,是为了调用其 appendChild 办法,把创立好的 PopoverComponent 实例,增加到 DOM 树中去。

  • changeDetectorRef: ChangeDetectorRef

在 SAP Spartacus 实现中没有用到。

  • positioningService: PositioningService

在 SAP Spartacus 实现中没有用到。

负责元素 focus 相干的实现。

  • winRef: WindowRef

负责将新建的 PopoverComponent 实例中的 DOM 元素,增加到以后 document 的 body 节点上。

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

【腾讯云】轻量 2核2G4M,首年65元

阿里云限时活动-云数据库 RDS MySQL  1核2G配置 1.88/月 速抢

本文由乐趣区整理发布,转载请注明出处,谢谢。

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据