andular js:无法删除我上传的文件

时间:2017-10-13 11:52:28

标签: jquery html angularjs

我是今天使用角度js的新手我试图上传文件并删除这个上传的文件,但现在我遇到了删除文件问题

这是我的html代码:

<div>
<ul>
    <li ng-repeat="files in table.process_data.attachments">
        <a target="_self" class="col-sm-6" href="sales/download/{{files.filepath}}/{{files.name}}">{{files.name}}</a> 
        <input type="button" class="btn btn-xs btn-danger col-sm-offset-3" ng-click="table.deleteFile(files.id)" value="delete"/>
    </li>
</ul>

这是我的angularjs删除功能:

 vm.deleteFile = function (id) {
            $scope.getJson('sales/removeAttachment', id, function (r) {
                if (r.error == null) {
                    vm.editSales(vm.edit_id);
                    vm.showToastSuccess('file deleted');
                } else {
                    vm.showToastFail(r.error);
                }
            });
        };

1 个答案:

答案 0 :(得分:1)

我认为这会帮助你!

vm.deleteFile = function (id) {
                $scope.getJson('file_upload/removeAttachment', id, function (r) {
                    if (r.success) {
                        vm.editSales(vm.edit_id);
                        vm.showToastSuccess('file deleted');
                    } else if (r.error) {
                        vm.showToastFail(r.error);
                    } else {
                        vm.showToastFail('something went wrong during delete!');
                    }
                });
            };