Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - ngModelController missing $validators?

I've been looking at Angular docs here: https://docs.angularjs.org/guide/forms#custom-validation

I'm trying to create my own input field validator using a custom directive. I've created a directive which seems identical to the one from the link above, only customized with my own validation function (6-digit password):

app.directive('password', function() {
   return {
       require: 'ngModel',
       link: function(scope, element, attrs, ctrl) {
           ctrl.$validators.password = function (modelValue, viewValue) {
               if (/^[0-9]{6}$/.test(viewValue)) {
                   return true;
               }

               return false;
           };
       }
   };
});

And when I run it, I get this error:

Error: ctrl.$validators is undefined

What am I missing here?

like image 831
morgoth84 Avatar asked Oct 18 '14 11:10

morgoth84


1 Answers

$validators only exist since version 1.3. Contrary to your comment the latest stable version is 1.3.0.

like image 128
a better oliver Avatar answered Oct 18 '22 16:10

a better oliver