javascript - What *is* the ngModel.$validators pipeline? -


while performing basic research on custom client-side validation in angular.js, reading ngmodel.ngmodelcontroller documentation, , found following cryptic line:

$setvalidity(validationerrorkey, isvalid); change validity state, , notifies form.

this method can called within $parsers/$formatters. however, if possible, please use ngmodel.$validators pipeline designed call method automatically.

a couple of hours , many google (and stackoverflow!) searches later, have found nothing ngmodel.$validators pipeline anywhere. custom validation examples use $parsers/$formatters setup below:

link: function (scope, elem, attr, ctrl) {     // other necessary logic...      ctrl.$parsers.push(function () {         // validation logic         ctrl.$setvalidity('validation-type', true);     });      ctrl.$formatters.push(function () {         // validation logic         ctrl.$setvalidity('validation-type', true);     }); }, 

question: angular documentation states above code not best practice, , mythical ngmodel.$validators pipline correct way go. have failed find information on better practice. how 1 use ngmodel.$validators correctly implement custom clientside validation?

$validators new angular 1.3. blog post gives explanation on how use them: http://www.yearofmoo.com/2014/09/taming-forms-in-angularjs-1-3.html#the-validators-pipeline

the basic idea add function onto ngmodel.$validators returns boolean specifying whether model valid.

then can refrence validator in html same way reference built in validators. e.g.

<div ng-if="myform.myfield.$error.myvalidator">     error message here </div> 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -