单击按钮后如何清除Angularjs中的输入字段

时间:2014-07-18 11:22:54

标签: html angularjs

点击一个按钮后,我需要清除一个文本框和一个选择列表。这是我尝试的但是它似乎不起作用:

HTML:

    <input type="text" ng-model="Model.CurrentDowntimeEvent.Comment" size="60" placeholder="ENTER IN ANY ADDITIONAL INFORMATION"/><br>
     <select class="categories" ng-disabled="selectlistdisabled"  ng-model="Model.CurrentDowntimeEvent.CategoryId" ng-options="downtimeCategory.CategoryId as downtimeCategory.CategoryName for downtimeCategory in Model.DowntimeCategories">     
   </select>
 <button ng-click="StopCurrentDowntime()">Stop Downtime Event</button>  

JS:

    angular.module('myApp', [])

     .controller('DowntimeController', function ($scope, $http) {
         $scope.Model = new Model($http);

     $scope.StopCurrentDowntime = function () {
             $scope.CurrentDowntimeEvent.Comment = '';
             $scope.CurrentDowntimeEvent.CategoryId = '';
}
});

2 个答案:

答案 0 :(得分:3)

不使用按钮清除输入字段,而是可以在表单中使用reset(input type =“reset”)

答案 1 :(得分:1)

你在JS中缺少Model.

angular.module('myApp', []).controller('DowntimeController', function ($scope, $http) {
   $scope.Model = new Model($http);

   $scope.StopCurrentDowntime = function () {
     $scope.Model.CurrentDowntimeEvent.Comment = '';
     $scope.Model.CurrentDowntimeEvent.CategoryId = '';
  }
});