我如何修复括号与点符号 Angularjs

How can I fix bracket vs dot notation Angularjs

问题很简单,我觉得下面的代码解释得更好

//指令

.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"

它会起作用。