在角度弹出窗口中加载 Pdf

问题描述 投票:0回答:1

我想在弹出窗口中加载 pdf,我尝试按照 https://stackblitz.com/edit/angular-modal-pdf?file=src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp 中的方式实现。组件.ts。此处 pdf 在弹出窗口中加载,但当我尝试动态添加链接时遇到问题。下面是我试过的代码。在这里我从打字稿传递 srclink 但它没有被分配

`<div #outsideElement>

  <div class="modal-view-container">
    <div #modalView class="modal view">
      <div class="modal-view-details">
        <p style="text-align: center;margin-top: 0; margin-bottom: 0">
          <object data="srclink" type="application/pdf" width="100%" height="592px;"> </object>
        </p>
      </div>
    </div>
  </div>
</div>`
angular modal-dialog
1个回答
0
投票

您可以通过Bindings将任何值绑定到您的视图。如果你想使用

One way binding
你已经改变了你的代码。

<p style="text-align: center;margin-top: 0; margin-bottom: 0">
      <object [data]="srclink" type="application/pdf" width="100%" height="592px;"> </object>
</p>

但是要在您的视图中绑定外部网址,您必须清理您的网址。

this.srclink = sanitizer.bypassSecurityTrustResourceUrl(
      "external_url_to_pdf"
);

我已经编辑了你的 stackblitz here upvote/accept if it helps

© www.soinside.com 2019 - 2024. All rights reserved.