添加到列表后清除输入

时间:2017-06-08 15:12:06

标签: angularjs

我在AngularJS应用程序中有以下HTML:

  <form name="form" ng-submit="vm.save(vm.data)">  
    <table>
      <tr ng-repeat="d in vm.data.degrees">
        <td ng-bind="d.school"></td>  
        <td ng-bind="d.field"></td>
      </tr>
    </table>
    <div>
      <input id="school" type="text" ng-model="d.school"/>
      <input id="field" type="text" ng-model="d.field"/>
      <button class="button" type="button" ng-click="vm.addDegree(d.school, d.field)">
        Add Degree
      </button>
    </div>       
    <input id="name" type="text" ng-model="vm.data.name"/>
    <button>Submit form</button>
  </button>        
</form>

我有一个按钮,可以将一个学位(d.school + d.field)添加到列表中(table)。 当我向列表中添加项目时,我想清除输入schooldegree

我该怎么做?

1 个答案:

答案 0 :(得分:3)

您可以在d.school指令中重置d.degreeng-click,如下所示:

ng-click="vm.addDegree(d.school, d.field);d.school = '';d.degree=''"

您可以查看this plunker