在提交时清除Angular表格

时间:2016-07-06 09:19:58

标签: angularjs html-form angularjs-forms

我正在尝试清除表单,但仍然面临一些问题。如何清除提交表单?

HTML

<form id="contact" class="contact-form" ng-submit="sendMail()" novalidate ng-controller="QuoteCtrl">
<div class="message"></div>
 <div class="col-md-5 col-sm-5 col-xs-12 animated hiding" data-animation="slideInLeft">
  <div class="form-group">
    <input type="text" name="name" class="nameform form-control input-lg" placeholder="name" ng-model="message.contactName" required>
  </div>     
</div>

<div class="col-md-7 col-sm-7 col-xs-12">
    <input type="submit" class="btn btn-custom up form-button" value="Send Message">

Angular

app.controller('QuoteCtrl', ['$scope', '$interval', '$http', 
function($scope, $interval, $http) {
    $scope.message = {};
   $scope.sendMail = function () {
      $http.post('/send/sendQuote', $scope.message).
        success(function(data) {
         $scope.message = data.message;
         console.log($scope.message);
         $scope.message = {};
      });
   }
}]);

清除表单的主要技巧有哪些,包括setPrestine()?

1 个答案:

答案 0 :(得分:1)

试试吧。它会正常工作

$http.post('/send/sendQuote', $scope.message).
        success(function(data) {
         $scope.message = data.message;
         console.log($scope.message);
         $scope.message.contactName=null;
      });