PiyaModi
PiyaModi

Reputation: 245

How to download file using angularjs?

In my application, there is a list of files. I stored this list in the scope.

I had put all files in data-table and i want to download the particular file on which user will click.

All types of file should acceptable.

Is there any directive to download the file as per my requirement.

Thanks!

Upvotes: 0

Views: 6416

Answers (1)

User44
User44

Reputation: 140

Try using the JavaScript library named FileSave: https://github.com/eligrey/FileSaver.js/

Call the following in your code:

saveAs(file, 'filename');

More importantly, try searching for this answer before posting, the answer can be found on this site right here: how to download file using AngularJS and calling MVC API?

UPDATE: Try the following:

<a download="content.txt" ng-href="{{ url }}">download</a>

This should create a download link for the file you specify.

Upvotes: 1

Related Questions