Angularjs simple file download -
html:
<a href="mysite.com/uploads/asd4a4d5a.pdf" download="foo.pdf">
uploads unique file name while there real name kept in database. want realize simple file download. code above redirects / because of:
$routeprovider.otherwise({ redirectto: '/', controller: maincontroller });
i tried
$scope.download = function(resource){ window.open(resource); }
but opens file in new window.
any ideas how enable real download file type?
https://docs.angularjs.org/guide/$location#html-link-rewriting
in cases following, links not rewritten; instead, browser perform full page reload original link.
links contain target element example:
<a href="/ext/link?a=b" target="_self">link</a>
absolute links go different domain example:
<a href="http://angularjs.org/">link</a>
links starting '/' lead different base path when base defined example:
<a href="/not-my-base/link">link</a>
so in case, should add target attribute so...
<a target="_self" href="example.com/uploads/asd4a4d5a.pdf" download="foo.pdf">
Comments
Post a Comment