title: How can I broadcast an object in Angularjs?
body: <p>How can I broadcast an object through an event?</p>
  
  <p>Currently I am trying:</p>
  
  <pre><code>app.run ($rootScope) -&gt;
      message = {type: 'channel', action: 'create', data: { name: "ssss", id: 0}}
      $rootScope.$broadcast('message', message)
  
  angular.module('WebChat').controller 'ChannelController', ($scope) -&gt; 
      $scope.$on 'message', (message) -&gt;
          console.log message
          console.log 'hi'
  </code></pre>
  
  <p>But I am getting no output</p>
  
  <p><strong>Edit</strong>
  I got it working. It seems that the first parameter of the callback function is the scope. I had to change the controller to:</p>
  
  <pre><code>angular.module('WebChat').controller 'ChannelController', ($scope) -&gt; 
      $scope.$on 'message', (scope, message) -&gt;
          console.log message
          console.log 'hi'
  </code></pre>