The code below seems to work pretty well for doing basic required form validation.
The form displays a red Name is required message when the field is dirty
Check out my angularJS form validaton on codpen link
I have showed an example how to validate required, minlength, maxlength, email, password case, confirm password match on my demo.
Here is the code:
var myApp = angular.module('myApp',[]);
myApp.controller('mainController',['$scope', function($scope) {
}]);
myApp.directive('validConfirmPassword', function() {
return {
require:'ngModel',
link: function(scope, elem, attrs, ctrl) {
ctrl.$parsers.unshift(function(viewValue, $scope) {
var noMatch = viewValue != scope.myForm.password.$viewValue;
ctrl.$setValidity('noMatch', !noMatch)
})
}
}
})
.content{ margin-top:50px; }
.danger-text { color: red; }