简体   繁体   English

提交POST AngularJS后表格未清除

[英]Form Not Clearing after submit POST AngularJS

I'm using angularjs frontend and Play framework backend to process posted data. 我正在使用angularjs前端和Play框架后端来处理发布的数据。

The challenge i'm facing is that the form is not resetting after successful posting of data I click submit. 我面临的挑战是成功单击我提交的数据后,表单不会重置。

My View is as below and is as below. 我的看法如下。

<form name="signupForm" ng-submit="signup()" novalidate>
 <div>
   <label for="email">Email</label>
   <input name="email" class="form-control" type="email" id="email" placeholder="Email"
          ng-model="email">
   </div>
 <div>
   <label for="password">Password</label>
   <input name="password" class="form-control" type="password" id="password"
          placeholder="Password" ng-model="password">

 </div>
 <button type="submit" class="btn btn-primary">Sign up!</button>
</form>

My Angular controller is as below 我的Angular控制器如下

angular.module('clientApp')
   .controller('SignupCtrl', function ($scope, $http, $log) {
     $scope.signup = function() {
       var payload = {
         email : $scope.email,
         password : $scope.password
       };

       $http.post('app/signup', payload)
           .success(function(data) {
             $log.debug(data);
           });
     };
   });

I'm using chrome browser. 我正在使用Chrome浏览器。 How do i get to clear the email and password fields after clicking submit? 单击提交后如何清除电子邮件和密码字段?

Set the $scope.email and $scope.password to null like $scope.email$scope.passwordnull例如

$http.post('app/signup', payload)
   .success(function(data) {
     $log.debug(data);

      $scope.email = null;
      $scope.password = null;
      $scope.signupForm.$setPristine(); //Set form to pristine mode
   });

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

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