Can you please explain the use use of data services vs the use of $rootScope events.
I have a list of say branches which provides edit functionality. On click of edit button I am broadcasting an event with root scope using
$rootScope.$broadcast('EditBranch', branchID);
This EditBranch
event is captured by edit/create controller which fetches the branch details and renders it in a proper edit format.
Other function is I am adding a new branch and I want it to be listed in existing branch list as soon as it is added. the code used is as follows
$rootScope.$broadcast('AddBranch', branchData); //in create controller
$scope.$on('AddBranch', function(e, branchData){ //in listing controller
$scope.branches.push(branchData);
});
Is it right to use $rootScope this way. Or should I create a shredService
for sharing branch data after I create it.