126
rated 0 times
[
132]
[
6]
/ answers: 1 / hits: 24368
/ 12 Years ago, sun, september 30, 2012, 12:00:00
How can I broadcast an object through an event?
Currently I am trying:
app.run ($rootScope) ->
message = {type: 'channel', action: 'create', data: { name: ssss, id: 0}}
$rootScope.$broadcast('message', message)
angular.module('WebChat').controller 'ChannelController', ($scope) ->
$scope.$on 'message', (message) ->
console.log message
console.log 'hi'
But I am getting no output
Edit
I got it working. It seems that the first parameter of the callback function is the scope. I had to change the controller to:
angular.module('WebChat').controller 'ChannelController', ($scope) ->
$scope.$on 'message', (scope, message) ->
console.log message
console.log 'hi'
More From » angularjs