0
我想在指令中的多个属性上设置公共观察者。我的代码如下在角度上设置指令的多个属性的观察者
.directive('myDirective', function() {
return {
restrict: 'A',
scope: true,
link: function ($scope, element, attrs) {
$scope.$watch(function() {
return [attrs.attrOne];
}, function (newVal) {
console.log(newVal);
}, true);
})
但这不起作用,我已经设置了对象相等的第三个参数为true。但是,如果我尝试设置观察家上只是单个属性,它工作正常,代码如下
.directive('myDirective', function() {
return {
restrict: 'A',
scope: true,
link: function ($scope, element, attrs) {
$scope.$watch(attrs.attrOne,
function (newVal) {
console.log(newVal);
});
});
谁能解释这细节,为什么这种行为发生如图所示?
@georgeawg,在普拉克你为什么要通过X与attr-一个= “{{X}}” 为什么不ATTR一= “X”,有没有在这里花括号 – madhur