【发布时间】:2016-09-12 02:21:35
【问题描述】:
我使用 angular 指令创建了valid-file 属性,因为文件输入(带有bootstrap filestyle plugin)看不到required 属性:
.directive('validFile',function(){
return {
require:'ngModel',
link:function(scope,el,attrs,ngModel){
//change event is fired when file is selected
el.bind('change',function(){
scope.$apply(function(){
ngModel.$setViewValue(el.val());
ngModel.$render();
})
})
}
}
})
我需要动态添加或删除valid-file 属性。
如果我使用
$("input").attr("valid-file");
什么都不会改变。
如果我使用$("input").attr("valid-file",true);,它将添加属性valid-file="true",但验证会中断。
你能给我一些建议吗?
这里是笨蛋http://plnkr.co/edit/Gcbb7r05VBTjbh9x5Ma8?p=preview
【问题讨论】:
-
在演示中它正在工作
-
不。我需要 而不是 。我也试过 .prop() 但结果是一样的。
-
你的结果是一样的。
-
也尝试使用$compile来添加attr...但没有。
标签: javascript jquery angularjs validation angularjs-directive