首页 > 解决方案 > DOM 不使用 componentFactory 渲染

问题描述

要求:ngx-extended-pdf-viewer使用 Angular 9 在弹出窗口中打开

问题:

 `ngx-extended-pdf-viewer` couldn't loaded

在 TS 中:

open(): void {
    const componentFactory = this.resolver.resolveComponentFactory(WindowComponent);
    let componentRef  = componentFactory.create(this.injector);
    this.applicationRef.attachView(componentRef.hostView);

    // get DOM element from component
    const domElem = (componentRef.hostView as EmbeddedViewRef < any > )
      .rootNodes[0] as HTMLElement;

    this.OpenWindow = window.open('', 'childwindow', 'width=400,height=400,left=150,top=200');
    this.OpenWindow.document.body.innerHTML = "";
    this.OpenWindow.document.body.appendChild(domElem);
  }

标签: angular

解决方案


推荐阅读