Javascript $watch无法使用阵列

Javascript $watch无法使用阵列,javascript,angularjs,Javascript,Angularjs,我正在观察数组,如果它发生变化,那么我想调用一个函数 $scope.$watch( $scope.aQuestions, function fncheckQuesCount(newValue, oldValue) { debugger; if (newValue === oldValue) { return; }

我正在观察数组,如果它发生变化,那么我想调用一个函数

$scope.$watch(
            $scope.aQuestions,
            function fncheckQuesCount(newValue, oldValue) {
                debugger;
                if (newValue === oldValue) {
                    return;
                } 
                else fnGetQues();
            });
这里$scope.aQuestions是一个数组

但当我运行这个程序时,它会将newValue和oldValue显示为未定义。

应该是

$scope.$watch("aQuestions",

这是因为angular需要一种反复检查值的方法

在您的版本中,只需传入数组的值(未定义)。当值更改时,angular不知道,因为它没有对数组的引用

应该是

$scope.$watch("aQuestions",

这是因为angular需要一种反复检查值的方法


在您的版本中,只需传入数组的值(未定义)。当值更改时,angular不知道,因为它没有对数组的引用

尝试替换
})}的code>,为true)(或使用
$watchGroup
)尝试替换
})}的code>,为true)(或使用<代码> $观察组< /代码>)作为一个补充,考虑使用<代码> $CavaCuffs<代码>作为添加,考虑使用<代码> $CavaCyts< /Cord>