angular-bootstrap-file-field
angular-bootstrap-file-field copied to clipboard
How to implement a button for remove selected file ?
Hello.
How to implement a button for remove selected file ?
Best Regards
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.
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>