我已经写了下面的角度指令,将“必需的”属性添加到所有儿童:定制角指令,包括名称中有破折号不起作用
.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);
}
}
});
我真想把它称为“需要所有“,但如果我重命名它,那么它不再工作。为什么“需要”工作而不是“要求全部”?
它实际上是[kebab-case,list-case,甚至脊柱病例](http://en.wikipedia.org/wiki/ Snake_case)。 Snake-case会导致'require_all' – 2014-09-12 12:17:12
@Plantface我在Angular docs上看到它被称为蛇案,尽管我可以看到维基百科再次证明我错了;-) – 2014-09-12 13:39:12
Arrrgh,谢谢。之前有过这个问题,但忘记了它。在我看来,这不是直觉行为! – fstr 2014-09-12 14:45:29