impregnable fiend impregnable fiend - 6 months ago 18
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 :)


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>