Angular IE9 file upload not working

I use this method to upload a file:

<input type="file" name="upload-file" ng-model= "excelFile" accept=".xlsx" onchange="angular.element(this).scope().fileChanged(this);" required="true" /> 

Create a fileChanged method in the controller

  $scope.fileChanged = function(files) { $scope.excelFile = files[0]; }; 

It works in FireFox, Chrome IE10, IE11, but in IE9 it shows that "files have a value of zero undefined".

+7
javascript angularjs internet-explorer
source share
5 answers

I had the same problem while loading image files. It worked fine in IE10 and later. Any version below 10, file download does not work. See This Link

IE9Issue: Downloading files using AngularJS

+3
source share

It's impossible. IE9 does not support file APIs.

You can refer to this question https://stackoverflow.com/a/464632/

+2
source share

It is not possible to use IE9 and below using your method. You have two possible ways: 1. Use the Flash loader in case of IE9 and below. Try to avoid this scenario 2. Use http://malsup.com/jquery/form/ , which will give you "some kind" of access to the file, as HTML 5 does :)

+2
source share

As mentioned, any file upload method that uses the FormData and File API will not work in IE9 because they are not available until IE10.

However, there are two angular modules that have a return method that will work with IE9 to load files that I know of:

I use the nervgh / angular-file-upload function since it does not require Flash.

+1
source share

I think this is because in IE the event is in window.event, and is not passed as an argument to the event handler. Therefore, ' this ' will be the root of doc or undefined in IE.

You can easily test it by placing console.log(this) in the event handler in IE. Check out the "Event Differences" section in this article .

I think you can use the angular ng-change built-in directive or just

 $scope.$watch('excelFile', function(newVal){ // implementation }) 

in area.

0
source share

All Articles