我试图从链接函数添加一个ng-class属性到自定义指令.但是在添加ng-class属性后使用编译功能时,会抛出类似"RangeError:超出最大调用堆栈大小"的错误
请参阅下面的代码
MyApp.directive('twinField',function($compile){
return {
restrict:'A',
require:'ngModel',
scope:{
fval:'='
},
link:function(scope,ele,attr,ctrl){
ctrl.$validators.compareTo=function(val){
//alert(scope.fval)
return scope.fval==val
}
scope.$watch('fval', function(newValue, oldValue, scope) {
ctrl.$validate()
});
ele.attr("ng-class","addForm.cpassword.$error.compareTo?'errorpswd':''")//=""
$compile(ele)(scope);
}
}
Run Code Online (Sandbox Code Playgroud)
})
当我直接在html中添加ng-class时它正在工作.