Belal Othman Belal Othman - 3 months ago 6
AngularJS Question

angularjs: I need reset form without showing required fields with red color

when save my form (user)
after that I need to reset it to save new user
If I reset just like that
user = {};
and try to save new user
all the mandatory fields are appear with red color

how can I reset my form to avoid the red color

Answer

you can reset it like below:

$scope.resetForm =  function() {
    $scope.user= {};
    $scope.formName.$setPristine();
    $scope.formName.$setValidity();
    $scope.formName.$setUntouched();
}

call this function from your save function success...

Comments