AngularJS在“新建"选项卡中打开PDF [英] AngularJS Opening PDF in New tab

查看:121
本文介绍了AngularJS在“新建"选项卡中打开PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是AngularJS的新手.我需要帮助才能摆脱以下提到的情况.我正在尝试在按钮单击的新选项卡中打开PDF文件.我正在解决的代码如下.新选项卡不会打开.任何指导将不胜感激.

I am very new to AngularJS. I need help to get out of the below situation mentioned. I am trying to open an PDF file in new tab on button click. The code i am working around is below. The new tab does not open up. Any guidance will be highly appreciated.

$http.get('/api/services/downloadpdf/' + scope.invoice.id, { responseType: 'arraybuffer' }).then(function (response) {
    var file = new Blob([response.data], { type: 'application/pdf' });
    file.name = 'invoice.pdf';
    var fileUrl = URL.createObjectURL(file);
    $window.open(fileUrl);
});

推荐答案

如果您有这样的文件链接,请输入

If you have file link just give like this, In html

<a target="_target" href="invoice.pdf" role="button">View</a>

在控制器中使用此

$http.get('/api/services/downloadpdf/' + scope.invoice.id, { responseType: 'arraybuffer' }).then(function (response) {
    var file = new Blob([response.data], { type: 'application/pdf' });
    file.name = 'invoice.pdf';
    var fileUrl = URL.createObjectURL(file);
    $window.open(fileUrl, '_blank');
});

这篇关于AngularJS在“新建"选项卡中打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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