title: Angular - can I $broadcast a message from outside an angular app?
body: <p>I have a scenario where I need non-angular code (in this case Facebook and Twitter JS sdk's) to broadcast an event that angular controllers can listen to. Why? After the initial page load, I load and revise content in the page via AJAX. The content has multiple like/tweet buttons attached (like a front page of blog/aggregator). I'd like to add event hooks when a click occurs on either Facebook "Like" button or Twitter "Share" button - there are a few of those in the page, and each is changing whenever new content is fetched (again, via ajax).</p>
  
  <p>Now, the SDK's handle this differently:</p>
  
  <h3>Twitter</h3>
  
  <pre><code>twttr.events.bind('click', function(event){
      // here I'd like to somehow
      // $rootScope.$broadcast("twitter:clicked", event.currentTarget)
  });
  </code></pre>
  
  <h3>Facebook</h3>
  
  <pre><code>FB.Event.subscribe("edge.create", function(resp) {
      // here I'd like to somehow
      // $rootScope.$broadcast("facebook:clicked", resp)
  });
  </code></pre>
  
  <h3>some controller</h3>
  
  <pre><code>app.controller("SomeController", ['$scope', function($scope) {
      $scope.$on("facebook:clicked", function(event, resp) {
          // do something with resp
      });
  
      $scope.$on("twitter:clicked", function(event, target) {
          // do something target
      });
  }])
  </code></pre>
  
  <p>The idea is to bind these event handlers once and then deal with the broadcasted message in the relevant controllers, even though these controllers are re-created whenever new content is fetched.</p>
  
  <p>So basically, what I'm looking for is a way to hook into an existing and already initialized angular app's <code>$rootScope</code> and <code>$broadcast</code> a message, despite not being a part of the app. Hope this makes sense. Thanks.</p>