我想检查范围内的每一项变化,并尝试以下内容:
$scope.$watch('$scope', function(newValue) {
console.log ("$scope's NewValue", newValue);
}, true);
我收到日志消息:
$scope's NewValue undefined
那是什么,尝试什么,有可能吗?
答案 0 :(得分:0)
我真的建议你不要这样做。它的申请费用很高。
$scope.$watch(function() { // First function must return the object that you want to watch.
return $scope;
},
function(newValue, oldValue) { // This is a callback executed everytime your $scope will change
console.log("$scope's NewValue : ", newValue); // You should rather use $log if you want to unit test your code one day
},
true // Needed to tell angular to watch deeply inside $scope (every sub item).
);