how we can get which validation is invalid in AngularJS -
i have code figure out if element valid or invalid in directive :
mymodule.directive('mydirective',function(){ return { restrict: 'a', scope: {}, require:'ngmodel', link: function(scope,element,attrs,ctrl){ if(ctrl.$invalid){ //do } } }});
so problem how can determine type of validation invalid, required? max-length? other custom-validations?
because need generate proper validation-message show.
ngmodelcontroller (or ctrl
, in example) has $error
property can use see validation errors are.
so if "required" validation has failed, property truthy: ctrl.$error.required
Comments
Post a Comment