1

I want to access the value of the FileList object when I Choose files using HTML input FileUpload. When I console.log this FileList object, I can see this object in the console window but I am not able to access the values using AngularJS.

This is my code:-

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<body>

<div ng-app="myApp" ng-controller="MyCtrl">

<input type="file" id="myFile" multiple size="50" ng-model="file" onchange="angular.element(this).scope().myFunction()">

<p id="demo" ng-repeat="file in fileList">
  Name: {{file.name}} </br>
  Type: {{file.type}} </br>
</p>
{{fileList}}

</div>
<script>
var app = angular.module('myApp', []);

app.controller('MyCtrl', ['$scope', function($scope){
 $scope.myFunction = function(){
    var x = document.getElementById("myFile");
    $scope.fileList = x.files;
    console.log($scope.fileList); 
 };
}]);

</script>
</body>
</html>

1 Answer 1

2

This directive has a pretty good API for working with files: https://github.com/danialfarid/ng-file-upload

The usage section has some examples you can follow, including ones that work with multiple files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.