impregnable fiend impregnable fiend - 1 year ago 91
AngularJS Question

How to automatize uploading files process in AngularJS?

I'm just learning so forgive me if my question is transparent. Now I've got in controller:

$scope.fileUrl = 'test/';
$scope.fileName = 'myData';

In html:

<a href="{{fileUrl}}" download="{{fileName}}"> Download version 1 </a>

So, maybe tomorrow I'll add in folder test file and then over and over again. Hence I will be forced to write almost the same line in the html & controller many times... How can I automatize that process? I hope what I have requested is possible, any help will be appreciated :)

Answer Source

you can store all your files in an array and iterate overthem with ng-repeat:

$scope.files = [{
        url: 'test/',
        name: 'myData'
    }, {
        url: 'test/',
        name: 'myData2'
    }, ... ];

in your html you write:

<a href="{{file.url}}" download="{{}}" ng-repeat="file in files"> Download version 1 </a>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download