[英]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.