Is it possible to force file downloads in browsers with angularjs? -
i'm have developed spa (single page application) angularjs , i'm trying force pdf file download angularjs.
by moment can open de pdf file in new tab next code.
html view:
<a ng-click="download()"></a>
controller:
$scope.download = function(){ $window.open('/cv.pdf', '_blank'); };
is there way force pdf download in browser?
you can see example in following urls:
www.juanmanuellopezpazos.es/curriculum (html view)
www.juanmanuellopezpazos.es/curriculum.pdf (pdf file download want force)
i done in mvc.net angular js. works fine firefox also(tested in version:50.0) write down following code in function:
//in mvc view <a ng-href="#" title="{{attachments.filename}} " ng-click="download(attachment.filepath,attachment.filename)">{{attachments.filename}} </a>
// in .js file $scope.download = function download(pathoffile, filename) { $http.get(pathoffile, { responsetype: "arraybuffer" }).then(function (response) { $scope.filedata = response.data; var headers = response.headers(); headers['content-disposition'] = "attachment"; var blob = new blob([response.data], { type: "octet/stream" }); var link = document.createelement('a'); link.href = window.url.createobjecturl(blob); link.download = filename; document.body.appendchild(link); link.click(); document.body.removechild(link); }); }
Comments
Post a Comment