[英]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'"
我想使用括號符號coz,這將是我必須在許多字段上使用的可重用指令。 但這是行不通的。 我究竟做錯了什么? 謝謝
變量attrs.personal
的內容還有一對引號。 更改為
personal = "INVALID_NAME"
它會工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.