diff --git a/src/AngularPublic.js b/src/AngularPublic.js index e97723ef946d..fce7d9449ba8 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -45,6 +45,8 @@ ngChangeDirective, requiredDirective, requiredDirective, + minlengthDirective, + maxlengthDirective, ngValueDirective, ngModelOptionsDirective, ngAttributeAliasDirectives, @@ -184,6 +186,8 @@ function publishExternalAPI(angular){ ngChange: ngChangeDirective, required: requiredDirective, ngRequired: requiredDirective, + ngMinlength: minlengthDirective, + ngMaxlength: maxlengthDirective, ngValue: ngValueDirective, ngModelOptions: ngModelOptionsDirective }). diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index f64084cd6935..dc121f89a5df 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1011,22 +1011,6 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { }; } } - - // min length validator - if (attr.ngMinlength) { - var minlength = int(attr.ngMinlength); - ctrl.$validators.minlength = function(value) { - return ctrl.$isEmpty(value) || value.length >= minlength; - }; - } - - // max length validator - if (attr.ngMaxlength) { - var maxlength = int(attr.ngMaxlength); - ctrl.$validators.maxlength = function(value) { - return ctrl.$isEmpty(value) || value.length <= maxlength; - }; - } } function weekParser(isoWeek) { @@ -2134,6 +2118,33 @@ var requiredDirective = function() { }; +var maxlengthDirective = function() { + return { + require: '?ngModel', + link: function(scope, elm, attr, ctrl) { + if (!ctrl) return; + var maxlength = int(attr.ngMaxlength); + ctrl.$validators.maxlength = function(value) { + return ctrl.$isEmpty(value) || value.length <= maxlength; + }; + } + }; +}; + +var minlengthDirective = function() { + return { + require: '?ngModel', + link: function(scope, elm, attr, ctrl) { + if (!ctrl) return; + var minlength = int(attr.ngMinlength); + ctrl.$validators.minlength = function(value) { + return ctrl.$isEmpty(value) || value.length >= minlength; + }; + } + }; +}; + + /** * @ngdoc directive * @name ngList