简体   繁体   中英

in IE9 uploadFile is not working

1 Add the file input box

<input type="file" id="uploadFile" ng-model="upFile" onchange="angular.element(this).scope().setFile(this)" />

2 Create the setFile method in the controller

$scope.setFile = function (element) {
    $scope.uploadedFile = element.files[0];
}

as above,I use this way to upload file ,it works in FireFox but in IE9 it shows that the "element is null our undefined". What can i do?

files is a HTML5 file api feature and works only on browsers that support it.

It's not supported in IE9 see: http://caniuse.com/#feat=fileapi

You can check if files is supported before use it, try (not tested):

if( ev.target.files ){
  $scope.uploadedFile = element.files[0];
}else{
  $scope.uploadedFile = ev.target.value;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM