Search code examples
angularjstwitter-bootstrapangularjs-directiveinput-type-fileangular-file-upload

Angular js Input type file - clear previously selected file


I am using input type="file" for my upload control using angular js. Everytime I click on browse, I do not want to see the previously selected file. By default,this seems to be retained. Can it be achieved by writing a directive? Can it be triggered everytime I click on browse?

I am using a bootstrap implementation to replace default browse button with some better.

 <span class="useBootstrap btn btn-default btn-file">
                Browse <input type="file"  />
            </span>

Solution

  • This was the easiest way, without using any directive or complex code.

    Browse <input type="file" ng-click="clear()" 
    

    And in your controller

     $scope.clear = function () {
        angular.element("input[type='file']").val(null);
    };