Open a PDF in a new window of the browser with angularjs

你说的曾经没有我的故事 提交于 2019-11-28 09:14:19
Mathew Berg

If you had something like this:

var myPdfUrl = 'something'
$http.get(myPdfUrl);

Do this instead:

var myPdfUrl = 'something'  
$window.open(myPdfUrl);

If instead you have something like this:

$http
    .get(generatePdfUrl)
    .then(function(data){
        //data is link to pdf
    });     

Do this:

$http
    .get(generatePdfUrl)
    .then(function(data){
        //data is link to pdf
        $window.open(data);
    });         
carton

Maybe this can help,in the case of you have something like this :

$http.get('generatePdfUrl')
  .then(function (data) {     // data is your url
      var file = new Blob([data], {type: 'application/pdf'});
      var fileURL = URL.createObjectURL(file);
  });

Then use your service in controller and do

$window.open(fileURL);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!