Created
December 3, 2014 09:00
-
-
Save aruss/01fba84941f158ac798e to your computer and use it in GitHub Desktop.
Dynamicaly add attributes, or a directive that can add directives, yo dawg!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.directive('uiDynamicAttr', function($compile, $parse) { | |
return { | |
restrict: 'A', | |
terminal: true, | |
priority: 100000, | |
link: function(scope, element, args) { | |
var expression = element.attr('ui-dynamic-attr'); | |
if (expression) { | |
var attributes = $parse(element.attr('ui-dynamic-attr'))(scope); | |
if (attributes) { | |
for (var i = 0; i < attributes.length; i++) { | |
var attribute = attributes[i]; | |
if (angular.isObject(attribute)) { | |
element.attr(attribute.name, attribute.value | ''); | |
} | |
else { | |
element.attr(attribute, ''); | |
} | |
}; | |
element.removeAttr('ui-dynamic-attr'); | |
$compile(element)(scope); | |
} | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
field.validation = [
{
name: 'required',
message: 'Value is required.'
},
{
name: 'ng-minlength',
value: 3
}
]