user1973757
user1973757

Reputation: 41

how to get event in an angularjs function

In this code event display undefined.

<div class="div1" ng-click="displayinfo(event)">
    sadfasf
</div>

$scope.displayinfo = function(event)
{
     alert(event);
}

can anyone help. thanks

Upvotes: 2

Views: 11730

Answers (2)

JSAddict
JSAddict

Reputation: 12427

Use $event instead of event. It is little hidden in the docs http://docs.angularjs.org/api/ng.directive:ngClick

Upvotes: 4

Michelle Tilley
Michelle Tilley

Reputation: 159105

Very close--but it's $event.

<div class="div1" ng-click="displayinfo($event)">
    sadfasf
</div>

$scope.displayinfo = function(event)
{
     alert(event);
}

Upvotes: 2

Related Questions