In this plunk the objective is to show an error message based on validation in the controller (instead of the built-ins required
or min-length
). Th
The Dmitry K's answer it's excellent.
I´m going to expand the answer.
//Function before show your form:
vm.showForm(form){
form.$setPristine();
form.$setUntouched();
form.myFieldName.$setValidity('myCustomValidationName', false);
//More code...
}
//funtion to validate field on "ng-change"
vm.validateField(form){
if(xxxx == yyy) //Make your own validation{
form.myFieldName.$setValidity('myCustomValidationName', true);
}else{
form.myFieldName.$setValidity('myCustomValidationName', false);
}
}
And the relevant HTML code: