Angularjs-使用angularjs中的锚标记下载pdf文件 [英] Angularjs- download pdf file using anchor tag in angularjs

查看:57
本文介绍了Angularjs-使用angularjs中的锚标记下载pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <   div     ng-controller   =  appController     ng-app   =  app >  
< a ng-href = C:\ Users \mvijayan \ Documents \ Visual Studio 2015 \Projects\AngularjsTraining \ AngularjsTraining \Pdf \ID DocLink Programmer Reference.pdf download = <跨度class =code-keyword> file.pdf > 大家好,请下载此pdf文件并开始您的季节< / a >
< / div >





我尝试了什么:



嗨朋友们,



i尝试使用angularjs下载pdf文件,但它不起作用,任何人都可以告诉我,如果你知道这个,请修改并回复我们的人< / pre>

解决方案

你好@ User-11148958,



你的意思是下载not working?我在 Plunker 中设置了一个快速示例[ ^ ]几乎使用了你的代码。当我单击 DOWNLOAD 链接时,它会打开浏览器的默认下载对话框。



因为您的链接不包含任何特定于角度的语句(例如 {{/*...*/}} ),你甚至不需要 ng-href 对于下载链接,但坚持使用纯HTML href 超引用属性。请参阅文档 [ ^ ]了解更多详情和示例。



以防万一链接不起作用,这是示例代码。要使下载链接正常工作,请创建一个空文件,将其命名为 download.pdf 并将其放在HMTL文件旁边。



< pre lang =html> <! - index.html - >
< !doctype html >
< html ng-app >
< head >
< script src = https://ajax.googleapis.com/ajax /libs/angularjs/1.5.8/angular.min.js\"> < / script >
< link rel = stylesheet href = http: //netdna.bootstrapcdn.com/twitter-bootstrap/2.0.4/css/bootstrap-combined.min.css\">
< / head >
< body >
< div >
< p > < a href = download.pdf download = < span class =code-keyword> file.pdf > 下载< / p >
< / body >
< / html >





如果您有任何其他问题,请告诉我。



Best,K。

<div ng-controller="appController" ng-app="app">
    <a ng-href="C:\Users\mvijayan\Documents\Visual Studio 2015\Projects\AngularjsTraining\AngularjsTraining\Pdf\ID DocLink Programmer Reference.pdf" download="file.pdf">Hi guys, Please download this pdf file and start Your season</a>  
</div>



What I have tried:

hi friends,

i tried for download the pdf file using angularjs but its not working can anyone please tell me and if you know this please modify and reply me guys</pre>

解决方案

Hi @User-11148958,

what do you mean by download is "not working"? I set up a quick example in Plunker[^] that uses pretty much your code. When I click the DOWNLOAD link, it opens the browser's default download dialog.

As your link does not contain any angular-specific statements (like e.g. {{/*...*/}}), you even should not need the ng-href for the download link, but stick with the plain HTML href hyper-reference attribute. See the docs[^] for more details and examples.

Just in case the Plunker link isn't working, this is the example code. To make the download link work, create an empty file, name it download.pdf and place it next to the HMTL file.

<!-- index.html -->
<!doctype html>
<html ng-app>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.0.4/css/bootstrap-combined.min.css">
  </head>
  <body>
    <div>
      <p><a href="download.pdf" download="file.pdf">DOWNLOAD</p>
  </body>
</html>



If you have any further questions, please let me know.

Best, K.


这篇关于Angularjs-使用angularjs中的锚标记下载pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆