Resetting form after submit in Angularjs

后端 未结 5 1247
情话喂你
情话喂你 2020-11-29 07:57

Hi I have a form which does update on button click.

 $scope.action = \"Update\";
  var id = $routeParams.editId;
  scope.item = updateRecord.get({ id: id })         


        
5条回答
  •  感动是毒
    2020-11-29 08:43

    1) To Remove the values in Form Fields and to reset you can use $setPristine();

    $scope.formName.$setPristine();
    

    2) Next, to set the form to Untouched State too use $setUntouched();

    (If you have required fields in your form Fields and also if you are using ng-messages then if you don't use the below function those fields will show error.)

    $scope.formName.$setUntouched();
    

提交回复
热议问题