I have a service that I would like to $watch itself for any changes using the following:
$rootScope.$watch('budgetService', function(newVal, oldVal){
console.log('updating balances...');
budgetService.updateBalances(); // updates some values in the object in response to changes made
this.budgetUpdated(); // fires budget updated event: $rootScope.$broadcast('event.budgetUpdated');
}, true); // true = deep watch of object since budgetServices contains nested data
Syntactically and logically it works, but any idea what trouble I'm possibly getting myself into by injecting $rootScope into a service and using it in this way? My alternative is to $watch the object for changes in my controller and fire the method I need on the same object, but that spreads logic across controller and model which doesn't feel correct.
Any thoughts/guidance greatly appreciated.
** And thanks to all who actively participate in this group. It has helped me greatly as I've come up to speed on AngularJS over the past few weeks.