Answer the question
In order to leave comments, you need to log in
How to properly validate a field in angular?
There is an input field, if the user enters into it a value that is already in the database, then I prescribe:
$scope.requiredName = false;
$scope.uniqueName = true;
$scope.requiredName = true;
$scope.uniqueName = false;
$scope.$watch('currentUser.username'
<div>
<input type="text" placeholder="Username" class="form-control" ng-model="currentUser.username" name="name" />
<span class="error text-small block" ng-if="Form.name.$dirty && requiredName">News is required</span>
<span class="error text-small block" ng-if="Form.name.$dirty && uniqueName">News is not unique</span>
</div>
Answer the question
In order to leave comments, you need to log in
Changing the value of a field is worth watching through ng-change ( dock on ng-change ).
In order for the model to be updated only on blur, you can set custom ng-model-options ( dock by ng-model-options ).
For validation, you should use the standard angular features for forms, here you can read about them:
dock about forms
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question