简体   繁体   English

如何在Angular 6的网络浏览器中打开本地存储的PDF?

[英]How can I open a locally stored PDF on a web browser in Angular 6?

For some reason, when I try to click on this link it tries to redirect me to it, and then reloads the page on a blank http://localhost:4200/ page without displaying the PDF. 出于某种原因,当我尝试单击此链接时,它将尝试将我重定向到该链接,然后将该页面重新加载到空白的http:// localhost:4200 /页面上而不显示PDF。 I had this concept working on another project, and I tried to do the same thing as I did before, but nothing that I'm doing seems to be working. 我曾在另一个项目上使用过这个概念,但我尝试做的事情与以前相同,但是我正在做的事情似乎没有任何作用。 I've made sure that the file exists and I've done my best to give it the correct file path. 我已确保该文件存在,并且已尽力为它提供正确的文件路径。 The file link is in the show-report.component.html as: 文件链接在show-report.component.html中为:

Report: <a href="backend\PDF\f-1543526335019.pdf" target="_blank">Test</a>

show-report.component.html show-report.component.html

<h2>Civil Grand Jury - Reports</h2>

<mat-accordion>
  <mat-expansion-panel *ngFor="let report of reports">
    <mat-expansion-panel-header>
      <mat-panel-title>
        {{ report._id }} {{ report.reportNum }}
      </mat-panel-title>
      <mat-panel-description>
        {{ report.reportTitle }}
      </mat-panel-description>
      <mat-panel-description>
        {{ report.reportDate }}
      </mat-panel-description>
    </mat-expansion-panel-header>
    Report: <a href="backend\PDF\f-1543526335019.pdf" target="_blank">Test</a>
    <mat-action-row>
      <button mat-button color="primary">ADD RESPONSE</button>
      <a mat-button color="primary">EDIT REPORT</a>
      <button mat-button color="warn" (click)="openDialog(report)">DELETE</button>
    </mat-action-row>
  </mat-expansion-panel>
</mat-accordion>

Picture of File Structure: 文件结构图:

档案结构

Any additional code/resources will be available upon request. 任何其他代码/资源将根据要求提供。

First, check if http://localhost:4200/backend/PDF/f-1543526335019.pdf really exists. 首先,检查http:// localhost:4200 / backend / PDF / f-1543526335019.pdf是否确实存在。

If so, try this 如果是这样,请尝试

<a href="/backend/PDF/f-1543526335019.pdf" target="_blank">Test</a>

Also, use forward slashes. 另外,请使用正斜杠。 Backward slashes are a Windows thing. 反斜杠是Windows的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Angular 9 中的字节数组打开 PDF? - How can I open a PDF from array of bytes in Angular 9? 如何允许Angular 5 Web应用程序在同一浏览器的多个选项卡中打开 - how to allow angular 5 web app to open in multiple tab in same browser 如何使用angular 2+在本地下载PDF? - How to download a PDF locally using angular 2+? 我无法在Angular 2中获取本地存储的变量值 - I can't get my locally stored variable value in my Angular 2 如何使用角度和离子框架在手机中打开浏览器的一半屏幕 - How I can open a browser half of the screen in my mobile using angular and ionic framework 如何在本地处理错误并跳过 Angular HTTP 拦截器? - How can I handle an error locally and skip an Angular HTTP interceptor? 如何通过单击链接在 Angular Front End Web App 的浏览器中下载或保存 .csv 文件? 浏览器投诉没有文件 - How can I download or save a .csv file in browser in Angular Front End Web App on click of a link? browser complaints no file 我如何关闭浏览器 window 和 angular? - how I can close browser window with angular? 如何让我的 Angular web 应用程序在移动 Chrome 中全屏打开? - How can I make my Angular web app open in fullscreen in mobile Chrome? 如何在我的 Angular 组件中打开其他 web 站点 - How I can open other web site inside my Angular Component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM