I am trying to upload multiple files that allow users to upload multiple files.
For first time I'm able to upload files but when I select second time it come twice and for third time file name will comes three times.
Here is my code:
<body ng-app='myApp' ng-controller='myCtrl'>
<input type="file" class="filePost" name="file" id="filePost" multiple="" ng-click='getSelectedFile()'>
<div id='files_list'>
<ul> </ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.getSelectedFile = function() {
$("#filePost").change(function() {
var ele = document.getElementById('filePost');
var result = ele.files;
for (var x = 0; x < result.length; x++) {
var file = result[x];
$("#files_list ul").append(
"<li class='list_item'>" + file.name + " " + "<span
class = 'remove' > X < /span>" +"</li > "
);
}
$(document).on('click', '.remove', function() {
var span_id = $(this.parentNode).text();
$(this).closest('li').remove();
});
});
}
});
</script>
</body>