quma
quma

Reputation: 5733

AngularJS broadcast -> on listener

In one controller I have the following broadcast:

$rootScope.$broadcast('handleCreatedUser', {message: 'Hallo'});

and in an other controller I have this one:

$rootScope.$on('handleCreatedUser', function(args) {
    alert('CreateUserResponseController : ' + args.message);
    });

and I always get as alert message: "undefined". Actually I don't know what I am doing wrong. Has anyone any idea? Thanks a lot!

Upvotes: 1

Views: 88

Answers (1)

hoeni
hoeni

Reputation: 3280

The Angular Docs say

The event listener function format is: function(event, args...)

so the args you want are the second argument, not the first so the following should work:

$rootScope.$on('handleCreatedUser', function(event, args) {
    alert('CreateUserResponseController : ' + args.message);
});

Upvotes: 3

Related Questions