Can you please discuss the difference between using data services and $rootScope events?
Let's say I have a list of branches with an edit functionality. When the edit button is clicked, I trigger an event using $rootScope like this:
$rootScope.$broadcast('EditBranch', branchID);
The 'EditBranch' event is then caught by the edit/create controller which retrieves the branch details for editing.
Another scenario is when I add a new branch and want it to immediately appear in the existing branch list. Here is the code used:
$rootScope.$broadcast('AddBranch', branchData); // in create controller
$scope.$on('AddBranch', function(e, branchData){ // in listing controller
$scope.branches.push(branchData);
});
Is it appropriate to use $rootScope in this manner? Should I instead consider creating a 'sharedService' for sharing branch data after creation?