问题很简单,我认为下面的代码更好解释
//指令
.directive('special', function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
element.on('focus', function(){
element.removeClass('error-form');
scope.$apply(function(){
alert(attrs.personal); //prints out 'INVALID_NAME'
scope.errors.INVALID_NAME = false; //updates as I'd like
scope.errors[attrs.personal] = false; //Should do the same as above but isn't
});
});
}
};
})
//字段中的代码(html)
personal="'INVALID_NAME'"
我想使用括号符号,因为它将是一个可重用的指令,我必须在很多字段上使用。但它不起作用。我究竟做错了什么?谢谢
最佳答案
变量attrs.personal
的内容有一对额外的引号。将其更改为
personal = "INVALID_NAME"
它会起作用。
关于javascript - 如何修复括号与点符号 Angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28568120/