NgModelController missing $ validators?

I watched Angular docs here: https://docs.angularjs.org/guide/forms#custom-validation

I am trying to create my own input validator using a special directive. I created a directive that seems identical to the one above, only with my own verification 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?

+7
angularjs validation angularjs-ng-model angular-ngmodel
source share
1 answer

$validators exists only since version 1.3. Unlike your comment, the latest stable version is 1.3.0.

+14
source share

All Articles