Q:

how we can get which validation is invalid in AngularJS

I have this code to figure out if the element is valid or invalid in my directive :
myModule.directive('myDirective',function(){
return {
    restrict: 'A',
    scope: {},
    require:'ngModel',
    link: function(scope,element,attrs,ctrl){

        if(ctrl.$invalid){
            //do something
        }
    }
}});

So my problem is how can I determine which type of validation is invalid, required? max-length? my other custom-validations?
Because I need to generate proper validation-message to show.

A:

NgModelController (or ctrl, in your example) has an $error property that you can use to see what the validation errors are.
So if the "required" validation has failed, this property will be truthy: ctrl.$error.required

