Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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>
share|improve this question

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.

share|improve this answer
    
That's pretty cool. Thanks! – Shashank Dec 3 at 17:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.