Since my task was quite simple, I decided to go the other way:
HTML:
<input type="file" file-input="files" /> <ul> <li ng-repeat="file in files">{{file.name}}</li> </ul>
JS:
.directive('fileInput', ['$parse', function ($parse) { return { restrict: 'A', link: function (scope, element, attributes) { element.bind('change', function () { $parse(attributes.fileInput) .assign(scope,element[0].files) scope.$apply() }); } }; }]);
This is actually a solution from this tutorial. Please note that this may also work with multiple files.
However, there is nothing wrong with Serginho's alternative, I think there is an easier way.
source share