Consider the following scenario with data coming from a service:
myService.var1
myService.var2
myService.var3
Typically, you would need to monitor each variable individually like this:
$scope.$watch(function(){
return myService.var1
}, function(newValue, oldValue) {
})
$scope.$watch(function(){
return myService.var2
}, function(newValue, oldValue) {
})
However, I am looking for a way to monitor all variables in one go.
I attempted the following methods, but encountered issues with each:
// This resulted in a maximum digest cycle iteration error
$scope.$watch(function(){
return {
var1: myService.var1,
var2: myService.var2
}
}, function(newValue, oldValue) {
})
Additionally, I tried:
$scope.myVar1 = myService.var1
$scope.myVar2 = myService.var2
// Unfortunately, this does not actually watch the service variables
$scope.$watchGroup(['myVar1', 'myVar2'], function(newValue, oldValue) {
})
Any suggestions on how to approach this?