How do I clear or reset data in a form in angularjs?

前端 未结 5 1362
误落风尘
误落风尘 2021-01-16 21:48

Been finding how to clear form data with the use of angular and $setPristine Function but still no results always gives me an error saying $setPristine is not a function. Ca

5条回答
  •  死守一世寂寞
    2021-01-16 22:05

    You can remove form field value by removing value of ng-model like

    Your code

    var CustDetails = {
                    cname: $scope.CusDetails.cname,
                    comname: $scope.CusDetails.comname,
                    tel: $scope.CusDetails.tel,
                    email: $scope.CusDetails.email
    
                }; 
    

    Replace with this

    $scope.CustDetails = {
                    cname: $scope.CusDetails.cname,
                    comname: $scope.CusDetails.comname,
                    tel: $scope.CusDetails.tel,
                    email: $scope.CusDetails.email
    
                }; 
    

    Your code

    customerForm.$setPristine(true);
    

    Replace with this

    $scope.CustDetails={};
    

提交回复
热议问题