Issue
I try to do the following
if ($scope.RetypePassword != $scope.resource.Password) {
$scope.resource.Password.$setValidity("missmatch", false);
} else {
$scope.resource.Password.$setValidity("missmatch", true);
}
but fail with this error
TypeError: Object doesn't support property or method '$setValidity'
What can the reason be?
resource.Password is databound to an input like this
<input type="password" ng-model="resource.Password" name="Password" />
Solution
You should not have form name resource
because you has model which already has object in resource
, try some different from name will solve your problem
like name=”myForm”
Markup
<form name="myForm">
<input type="password" ng-model="resource.Password" name="Password" />
</form>
Code
if ($scope.RetypePassword != $scope.resource.Password) {
$scope.myForm.Password.$setValidity("missmatch", false);
} else {
$scope.myForm.Password.$setValidity("missmatch", true);
}
Answered By – Pankaj Parkar
Answer Checked By – Dawn Plyler (AngularFixing Volunteer)