TypeError: Cannot set property '$pristine' of undefined

1.7k views Asked by At

I am using AngularJS v1.3.16. I want to reset the form.

I tried $pristine, $dirty and $setPristine() but I got error messages:

HTML:

<form id="userForm" class="form-horizontal ut-form form-validation" role="form" name="userForm" novalidate>
.........
</form>

Code:

    $scope.createUser = function () {
        $scope.page.view = 'create';
        $scope.account = "";
        $scope.userForm.$pristine = true;
    }

Error messages:

  1. $setPristine() - TypeError: Cannot read property '$setPristine' of undefined

  2. $pristine - TypeError: Cannot set property '$pristine' of undefined

Please can any one suggest me how to solve this problem.

1

There are 1 answers

2
Carsten On

you can use the form name for this.

In your case:

$scope.userForm.$setPristine()

Or directly in the HTML:

userForm.$setPristine()