Html 在提交后无法清除表单字段

Html 在提交后无法清除表单字段,html,angularjs,forms,Html,Angularjs,Forms,我是个新手。我在提交后查找了很多关于清除表单字段的答案,但似乎没有一个有效。 以下是我的HTML代码: <form name="myForm" ng-submit="formSubmit()" class="form-horizontal"> <div class="form-group"> <input type="text" class="form-control" ng-model="user.FullName" placeh

我是个新手。我在提交后查找了很多关于清除表单字段的答案,但似乎没有一个有效。 以下是我的HTML代码:

  <form name="myForm" ng-submit="formSubmit()" class="form-horizontal">

      <div class="form-group">

       <input type="text" class="form-control" ng-model="user.FullName" placeholder="Full Name" required=""/>

      </div>
      <div class="form-group">
      <input type="text" class="form-control" ng-model="user.Address" placeholder="Address" required=""/>
         </div>
     <button type="submit" class="btn btn-primary" style="background-color: purple;">Submit</button>

 </form>

我尝试过setPristine和SetUntouch,但都不起作用。

我没有看到你的代码中有什么奇怪的地方,我根据你的代码制作了plnkr,我所做的修改如下。也把plnkr

控制器

var myApp = angular.module('myApp', ['ui.router']); 
 myApp.controller("RegisterCtrl", function ($window,$scope,$http) {
   $scope.user={}
   $scope.formSubmit=function(){
     $http({
        method:'POST',
        url:'myurl',
        data:$scope.user,
        headers:{'Content-Type':'application/json'}
    }).then(function(res){
        $scope.myForm.$setPristine();
        $scope.user = {};
      }, function(rej){ //error});
 }
 });

我没有看到你的代码有什么奇怪的地方,我根据你的代码做了plnkr,我做的修改如下。也把plnkr

控制器

var myApp = angular.module('myApp', ['ui.router']); 
 myApp.controller("RegisterCtrl", function ($window,$scope,$http) {
   $scope.user={}
   $scope.formSubmit=function(){
     $http({
        method:'POST',
        url:'myurl',
        data:$scope.user,
        headers:{'Content-Type':'application/json'}
    }).then(function(res){
        $scope.myForm.$setPristine();
        $scope.user = {};
      }, function(rej){ //error});
 }
 });
你应该试试

var myApp = angular.module('myApp', ['ui.router']); 
 myApp.controller("RegisterCtrl", function ($window,$scope,$http) {
   $scope.user={}
   $scope.formSubmit=function(){
     $http({
        method:'POST',
        url:'myurl',
        data:$scope.user,
        headers:{'Content-Type':'application/json'}
    }).then(function(res){
        $scope.$broadcast('show-errors-reset');
        $scope.forms.user = {};
        $scope.forms.userFrom.$setPristine = true;
      }, function(rej){ //error});
 }
 });
你应该试试

var myApp = angular.module('myApp', ['ui.router']); 
 myApp.controller("RegisterCtrl", function ($window,$scope,$http) {
   $scope.user={}
   $scope.formSubmit=function(){
     $http({
        method:'POST',
        url:'myurl',
        data:$scope.user,
        headers:{'Content-Type':'application/json'}
    }).then(function(res){
        $scope.$broadcast('show-errors-reset');
        $scope.forms.user = {};
        $scope.forms.userFrom.$setPristine = true;
      }, function(rej){ //error});
 }
 });

这个问题的标签不正确。这个论坛是为angular 2+设计的。请把标签换成angularjs@RRForUI这不是论坛,您可以建议编辑以更改标记。此问题的标记不正确。这个论坛是为angular 2+设计的。请把标签换成angularjs@RRForUI这不是一个论坛,您可以建议编辑以更改标记。由于未进入承诺的成功状态,您可能无法工作,请尝试放置
$scope.myForm.$setPristine()也像我的plnkr一样在rejec中。可能不是你的,因为没有进入承诺的成功状态,请尝试放置
$scope.myForm.$setPristine()也在rejec中,就像我的plnkr一样。