0

1 添加文件输入框

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

2 在控制器中创建setFile方法

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

如上所述,我使用这种方式上传文件,它在 FireFox 中有效,但在 IE9 中显示“元素为空,我们未定义”。我能做些什么?

4

1 回答 1

0

files是 HTML5 文件 api 功能,仅适用于支持它的浏览器。

IE9 不支持它,请参阅:http ://caniuse.com/#feat=fileapi

您可以files在使用前检查是否支持,尝试(未测试):

if( ev.target.files ){
  $scope.uploadedFile = element.files[0];
}else{
  $scope.uploadedFile = ev.target.value;
}
于 2013-05-01T16:19:30.923 回答