【发布时间】:2014-07-07 12:25:32
【问题描述】:
我一直在尝试创建一个非常简单的指令来检查属性my-minlength 是否为字符串(非空)以及是否为;将属性ng-minlength 添加到输入元素。我觉得这应该可行,但它根本行不通。
我的指令
var app = angular.module("fooApplication", [])
app.directive('myMinlength', function() {
return {
link: function(scope, element, attrs) {
if(element == "") {
attrs.$set('ng-minlength', attrs.myMinlength);
}
},
}
});
我的 HTML
<input type="text" name="foo" my-minlength="5" required/>
编辑建议完全消除可能的错误 - 仍然不起作用。
.directive('myMinlength', ['$compile', function($compile) {
return {
link: function(scope, element, attrs) {
if(true) {
attrs.$set('ng-minlength', "5");
$compile(element)(scope);
}
},
}
}]);
【问题讨论】:
标签: angularjs angular-directive