javascript - 如何修复括号与点符号 Angularjs

标签 javascript angularjs angularjs-directive angularjs-scope

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

//指令

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

相关文章:

javascript - 在框架中将 Javascript 变量传递给 '<a href' 并使用 'window.location.href'

javascript - javascript 新手,为什么我的按钮不起作用?

javascript - JS函数在大于或小于之间切换

javascript - AngularJS ui-chart 在 ui-bootstrap 选项卡中不起作用

android - 从 ionic 生成非调试 apk

angularjs - ng-model 不适用于 select 指令

angularjs - 在隔离范围内声明复杂对象

javascript - Azure Functions [Node.js] : context. BindingData 不包含我的路由参数(如文档所示)

javascript - Textarea ng-bind,其中值有前缀和后缀

angularjs - 测试 mousedown、mousemove、mouseup Angular