matt2mi
matt2mi

Reputation: 154

AngularJS - Event fired only once

I've got this in a first controller : (executed on ng-mouseover)

$scope.overMenu = function() {
    $rootScope.$broadcast('overMenu');
    console.log('overMenu');
};

And this in a second one :

$scope.$on('overMenu', $scope.overMenu());
$scope.overMenu = function()
{
    console.log('on overMenu');
    //gridLayoutPlugin.updateGridLayout();
};

But my event is fired or catched only once and i don't understand why...

Upvotes: 1

Views: 1328

Answers (2)

matt2mi
matt2mi

Reputation: 154

Solved !

I started over everything and putting my $scope.$on at the end of my controller, i don't remember but maybe i declared it before the function i wanted to call...

Upvotes: 1

dfsq
dfsq

Reputation: 193261

Event handler should be a function reference:

$scope.$on('overMenu', $scope.overMenu);

When you put parentheses after function name you immediately invoke it. What you want to do is to provide a reference to a function to be called on once event occures.

Upvotes: 0

Related Questions