javascript Angular IE9 文件上传不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25472254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:33:10  来源:igfitidea点击:

Angular IE9 fileupload is not working

javascriptangularjsinternet-explorer

提问by Shankar Kamble

I use this way to upload file:

我用这种方式上传文件:

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

Create the fileChanged method in the controller

在控制器中创建 fileChanged 方法

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

It works in FireFox, Chrome IE10, IE11, but in IE9 it shows that the "files is null our undefined".

它适用于 FireFox、Chrome IE10、IE11,但在 IE9 中它显示“文件为空我们的未定义”。

回答by Janaki Sathiyamurthy

I faced the same issue when uploading image files. It worked fine in IE10 and later versions. Any version below 10 , file upload is not working. Refer this link

上传图像文件时我遇到了同样的问题。它在 IE10 及更高版本中运行良好。任何低于 10 的版本,文件上传都不起作用。参考这个链接

IE9Issue : File Upload using AngularJS

IE9Issue :使用 AngularJS 上传文件

回答by Vedran Maricevic.

There is no way to use IE9 and below with the your method. You have two possible ways: 1. Use Flash uploader in case of IE9 and lower. Try to avoid this scenario 2. Use the http://malsup.com/jquery/form/which will give you "some sort" of file access, as HTML 5 does :)

您的方法无法使用 IE9 及以下版本。您有两种可能的方法: 1. 在 IE9 及更低版本的情况下使用 Flash 上传器。尽量避免这种情况 2. 使用http://malsup.com/jquery/form/这会给你“某种”文件访问,就像 HTML 5 那样:)

回答by KennyE

As mentioned any method of file upload that uses FormData and File API stuff won't work in IE9 as they aren't available until IE10.

如前所述,任何使用 FormData 和 File API 内容的文件上传方法都无法在 IE9 中使用,因为它们在 IE10 之前不可用。

However, two angular modules that have a fallback method that will work with IE9 for uploading files that I know of are:

但是,两个具有回退方法的 angular 模块可以与 IE9 一起使用以上传我所知道的文件:

I am using nervgh/angular-file-upload as it does not require Flash.

我正在使用 nervgh/angular-file-upload,因为它不需要 Flash。

回答by Nicolas S.Xu

I think it is because in IE the event is in window.event, not passed in as parameter to the event handler. Therefore, the 'this' will be the doc root or undefined on IE.

我认为这是因为在 IE 中事件在 window.event 中,而不是作为参数传递给事件处理程序。因此,“ this”将是文档根目录或在 IE 上未定义。

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

您可以通过console.log(this)在 IE 上放置事件处理程序来轻松测试它。退房的事件不同部分这篇文章

I think you can use a native angular directive ng-change, or just

我认为你可以使用原生角度指令 ng-change,或者只是

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

in the scope.

范围内。