function register(id, scope, success, error)
{
var handler = $rootScope.$on('settings:get' + id + scope.$id, success);
scope.$on('$destroy', handler);
// some code
$rootScope.$emit('settings:get' + id + scope.$id, settings);
}
- side effect if missing
+ id + scope.$id
is that 2 controllers call register(id, $scope, success, error)
, when $emit
occurs, it notify 2 controllers
- use unique text by combine scope.$id + some information (like id or keyword, ...) avoid side effect.
- the function can't use by factories because they don't have $scope