如何使用Angularjs在Internet Explorer中上载文件后清除文件名

时间:2022-05-28 23:15:37
<input type="file" ng-model="myobj.file" ng-file-select="onFileSelect_filter($files)" id="fileButton" >
<button type="button" ng-click="start_Filter();" >Upload</button>

and my onFileSelect_filter() function goes like this,

我的onFileSelect_filter()函数是这样的,

$scope.onFileSelect_filter = function($files){
   ....
};

I want to clear the file name after i click the Upload button in Internet Explorer atleast.

我至少在Internet Explorer中单击“上载”按钮后,我想清除文件名。

This input box is not inside the form Thanks in advance...!!!

此输入框不在表单内,提前感谢... !!!

4 个解决方案

#1


1  

Unfortunately, equating the bound $scope variables to empty string or null will not work in this case.

不幸的是,将绑定的$ scope变量等同于空字符串或null在这种情况下将不起作用。

Although you can achieve it by 1 of the below mentioned ways.

虽然你可以通过以下提到的方式之一来实现它。

Method 1 :

方法1:

You have to literally replace the html on the DOM on-click(on upload in your case) and revert it to how it was before upload. Like so..

您必须逐字地替换DOM上的html(在您的情况下上传)并将其恢复为上载前的状态。像这样......

 $scope.start_Filter = function(){
   // This is in the upload function post all your logic
   $("#fileButton").replaceWith("<input type='file' ng-model='myobj.file' ng-file-select='onFileSelect_filter($files)' id='fileButton' >").html();
};

Note : You MUST use single-quotes instead of double-quotes for all the HTML attribute values inside the replaceWith function

注意:必须对replaceWith函数中的所有HTML属性值使用单引号而不是双引号

Method 2 :

方法2:

Alternatively you can easily clear the filename using JQuery. Like so..

或者,您可以使用JQuery轻松清除文件名。像这样......

$scope.start_Filter = function(){
   // This is in the upload function post all your logic
   $("#fileButton").val('');
};

One of these should work. Please try them and let me know if you face any troubles.

其中一个应该工作。如果您遇到任何麻烦,请试试并告诉我。

#2


1  

The simplest way is : angular.element("input[type='file']").val(null);

最简单的方法是:angular.element(“input [type ='file']”)。val(null);

#3


0  

In your Controller, after file upload completed change the myobj.file value.

在Controller中,文件上载完成后更改myobj.file值。

$scope.myobj.file = ''

#4


0  

Try clearing the $scope.myobj var:

尝试清除$ scope.myobj var:

$scope.onFileSelect_filter = function($files){
    $scope.myobj.file = undefined;
};

#1


1  

Unfortunately, equating the bound $scope variables to empty string or null will not work in this case.

不幸的是,将绑定的$ scope变量等同于空字符串或null在这种情况下将不起作用。

Although you can achieve it by 1 of the below mentioned ways.

虽然你可以通过以下提到的方式之一来实现它。

Method 1 :

方法1:

You have to literally replace the html on the DOM on-click(on upload in your case) and revert it to how it was before upload. Like so..

您必须逐字地替换DOM上的html(在您的情况下上传)并将其恢复为上载前的状态。像这样......

 $scope.start_Filter = function(){
   // This is in the upload function post all your logic
   $("#fileButton").replaceWith("<input type='file' ng-model='myobj.file' ng-file-select='onFileSelect_filter($files)' id='fileButton' >").html();
};

Note : You MUST use single-quotes instead of double-quotes for all the HTML attribute values inside the replaceWith function

注意:必须对replaceWith函数中的所有HTML属性值使用单引号而不是双引号

Method 2 :

方法2:

Alternatively you can easily clear the filename using JQuery. Like so..

或者,您可以使用JQuery轻松清除文件名。像这样......

$scope.start_Filter = function(){
   // This is in the upload function post all your logic
   $("#fileButton").val('');
};

One of these should work. Please try them and let me know if you face any troubles.

其中一个应该工作。如果您遇到任何麻烦,请试试并告诉我。

#2


1  

The simplest way is : angular.element("input[type='file']").val(null);

最简单的方法是:angular.element(“input [type ='file']”)。val(null);

#3


0  

In your Controller, after file upload completed change the myobj.file value.

在Controller中,文件上载完成后更改myobj.file值。

$scope.myobj.file = ''

#4


0  

Try clearing the $scope.myobj var:

尝试清除$ scope.myobj var:

$scope.onFileSelect_filter = function($files){
    $scope.myobj.file = undefined;
};