为什么不是范围。$ watch工作?

时间:2013-05-06 15:55:11

标签: angularjs angularjs-directive

请看这个小提琴:

http://jsfiddle.net/sDnN5/

scope.$watch('points', function (value) {
    scope.console.push('scope.$watch');
});

出于某种原因,$scope.points更改

时不会触发
$scope.points.push(1);

为什么?

编辑澄清:

我希望看到这个:

events: ["scope.$watch","testUpdate()","scope.$watch","testUpdate()","scope.$watch","testUpdate()"]

但相反,我看到了这一点:

events: ["scope.$watch","testUpdate()","testUpdate()","testUpdate()"]

请注意缺少scope.$watch es

1 个答案:

答案 0 :(得分:3)

好的,在属性函数watch中添加true:

scope.$watch('points', function (value) {
    alert('totowatch');
    scope.console.push('scope.$watch');
},true);