I have been trying to create a very simple directive that checks if the attribute my-minlength
is a string (not null) and if it is; add the attribute ng-minlength
to the input element. I feel like this should work, but it is simply not working.
My Directive
var app = angular.module("fooApplication", [])
app.directive('myMinlength', function() {
return {
link: function(scope, element, attrs) {
if(element == "") {
attrs.$set('ng-minlength', attrs.myMinlength);
}
},
}
});
My HTML
<input type="text" name="foo" my-minlength="5" required/>
Edit the suggestion completely stripped from possible errors - still does not work.
.directive('myMinlength', ['$compile', function($compile) {
return {
link: function(scope, element, attrs) {
if(true) {
attrs.$set('ng-minlength', "5");
$compile(element)(scope);
}
},
}
}]);