Simple custom directive add ng-attribute to input element

Monday, July 7, 2014

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/>






http://ift.tt/1odO0np