Reputation:
I want to check for fun every changes in the scope and I've tried the following:
$scope.$watch('$scope', function(newValue) {
console.log ("$scope's NewValue", newValue);
}, true);
I get the log message:
$scope's NewValue undefined
Is that, what am trying, is possible anyway?
Upvotes: 1
Views: 706
Reputation: 11397
I really suggest you to not do this. It will have a high cost in your application.
$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).
);
Upvotes: 1