prince
prince

Reputation: 611

How can I download the files using AngularJS?

I want to list all the files in <a></a> when clicking it we need to download it from the corresponding folder.

I tried the following code

<div ng-repeat="file in files"> 
 <a download="{{file.name}}" href="/path of the file">{{file.name}}</a> 
</div>

How can I achieve this?

Can anyone help me?

Upvotes: 0

Views: 3808

Answers (1)

Jim Schubert
Jim Schubert

Reputation: 20357

If you have an anchor tag that you'd like to not be processed by angular, you'll need to use target="_self" or some other valid target.

See the $location documentation

This should work for you:

<div ng-repeat="file in files"> 
 <a target="_self" download="{{file.name}}" href="/path of the file">{{file.name}}</a> 
</div>

Another option may be to use the full path to the filename, but this doesn't seem to work in every case.

Here's a plunker with examples.

Upvotes: 2

Related Questions