angular-bootstrap-file-field icon indicating copy to clipboard operation
angular-bootstrap-file-field copied to clipboard

How to implement a button for remove selected file ?

Open tgarijo opened this issue 9 years ago • 2 comments

Hello.

How to implement a button for remove selected file ?

Best Regards

tgarijo avatar Jul 21 '16 14:07 tgarijo

I wired up a conditional that displays a delete button if the item has a previewImage value set:

         <button type="button"  
             ng-show="$ctrl.item.previewImage" 
             ng-click="$ctrl.removePreviewImage($ctrl.item)"
          class="btn btn-default">
                   <span class="Close_Window_Icon">X</span> 
        </button> 

Then created a function in the controller:

        function removePreviewImage(item) {
            delete item.uploadImage;
            delete item.previewImage;
            delete item.fileName;
        };

The only trouble I'm having is that if you attach a file, then delete it, you can't attach the same file again. You can delete a file and attach a different file, that works, but you can't attach the same file you've deleted and I have no idea why.

alignsoft avatar Sep 29 '16 17:09 alignsoft

I ran into this same issue with deleting a file and not being able to attach the same file again. I was able to work around it by re-initializing the directive with ng-if like the following:

<file-field ng-if="!ctrl.add.file" ng-model="ctrl.add.file">Add File</file-field>
<div ng-show="ctrl.add.file.name">
  {{ctrl.add.file.name}} <button ng-click="ctrl.add = {}">remove</a>    
</div>

jwenerd avatar May 25 '17 15:05 jwenerd