I wrote the following Angular directive, which will add the “required” attribute for all children:
.directive("requireall", function($compile) { return { restrict: 'A', //only want it triggered for attributes compile: function(element, scope) { // Prevent infinite loop on compile element.removeAttr("requireall"); var allChildren = element.find('*'); allChildren.attr('required', 'required'); $compile(element)(scope); } } });
I really want to call it "require-all", but if I rename it, then it no longer works. Why is “required” but not “required by all”?
angularjs angularjs-directive
fstr
source share