Generally, you shouldn't inject $rootScope
all over the place. It can often becomes a crutch and you'll end up having a lot of "global variables"
I'd either build a service that abstracts the $rootScope.broadcast
call, or simply use databinding instead:
<my-directive text-search="foo"></my-directive>
with a controller like:
.directive('myDirective', [function() {
return {
link: function($element, $scope, $attrs) {
$scope.$watch($attrs.textSearch, function(newValue, oldValue) {
// Do stuff here...
});
}
};
}]);