简体   繁体   English

使用angularjs清除输入字段

[英]Clear input field using angularjs

Let me rephrase my question, I have a problem, with deleting uploaded files, so I've made some modification to my code as suggested but It still does not work, further more there is a problem of overwriting my uploaded files, so every time I upload something it will just overwrite previous file, and I want to be able to upload many and delete them, thanks 让我重新表达一下我的问题,删除上传的文件时遇到了问题,因此我按照建议对代码进行了一些修改,但仍然无法正常工作,此外还有覆盖我上传的文件的问题,因此每次我上传了一些内容,它将覆盖以前的文件,并且我希望能够上传许多文件并将其删除,谢谢

<form class="htmlForm">
  <label for="id_payment_proof">{% trans "Payment proof:" %}</label>
  <div class="full-size">
    <div class="input-control full-size file" data-role="input">
      <input id="id_payment_proof" type="file" file-model="payment_proof"/>
      <button class="button"><span class="mif-folder"></span></button>
    </div>
  </div>
  <div ng-if="client_invoice.payment_proof_filename">
    <a ng-href="{{ client_invoice.payment_proof }}"
    ng-bind="client_invoice.payment_proof_filename"
    target="_blank"></a>
    <button class="button" ng_click="clearInvoice()">
      <span class="mif-bin"></span>
    </button>
  </div>
  {% endverbatim %}
</form>

controler: 控制者:

editInvoiceHandler = (event, row) ->
$scope.payment_proof = undefined
$scope.htmlFormEl.reset()
$scope.row = row
$scope.client_invoice = row.data()
hasChanges = false
$scope.editMode = true
$scope.$digest()

$scope.clearInvoice() = () ->
$scope.payment_proof = 0

I didn't test the code below but think it might be similar to what you need: 我没有测试下面的代码,但认为它可能与您需要的类似:

$scope.payment_proof = []; // presume you don't want any pre-loaded entries
$scope.add(new_entry) = payment_proof.push(new_entry);
$scope.delete(index) = payment_proof.splice(index,1);
$scope.clearInvoice = {  $scope.payment_proof = [];  }
//Then submit the payment_proof to the back end

The idea is to manipulate an array ( payment_proof in your case) and submit it to the back end. 这个想法是操纵一个数组(在您的情况下为payment_proof )并将其提交到后端。

In your controller : 在您的控制器中:

$scope.deleteUploadedFile = function () {
  $scope.payment_proof = null 
}

尝试这个

<button class="button" ng-click="payment_proof = ''"> Delete</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM