Skip to content

Instantly share code, notes, and snippets.

@hartzis
Created October 25, 2014 19:55
Show Gist options
  • Save hartzis/83b51a916fcd10f1908d to your computer and use it in GitHub Desktop.
Save hartzis/83b51a916fcd10f1908d to your computer and use it in GitHub Desktop.
iframe download file angular without jquery
.directive('fileDownload', function ($compile) {
var fd = {
restrict: 'A',
link: function (scope, iElement, iAttrs) {
scope.$on("downloadFile", function (e, url) {
// console.log('dl url-', url);
var iFrame = iElement.find("iframe");
if (!(iFrame && iFrame.length > 0)) {
iFrame = angular.element("<iframe style='position:fixed;display:none;top:-1px;left:-1px;'/>");
iElement.append(iFrame);
}
iFrame.attr("src", url);
});
}
};
return fd;
});
@mnishihan
Copy link

Wondering why you need to inject $compile service into the directive, even though it was not used anywhere??

@dasarikarthik81
Copy link

I'm using the same code, I have an issue when I want to download multiple files than previous download service call is getting canceled. I want same multiple downloaded. Did you face this issue

Code usage

then file download directive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment