Get event information using angularjs -
i trying track button clicks user performs on page/view. trying element idwhich clicked.
is there way without having tie function or directive each element?
ng-controller
, ng-click
html:
<body ng-controller="mycontroller" ng-click="go($event)"> <div id="box1"> <div id="box2"> <div id="box3"></div> </div> </div> </body>
js:
$scope.go = function(e) { var clickedelement = e.target; console.log(clickedelement); console.log(clickedelement.id); };
demo: http://plnkr.co/edit/1o6pcvrvgu7bl8b6tlpf?p=preview
directive:
html:
<body my-directive> <div id="box1"> <div id="box2"> <div id="box3"></div> </div> </div> </body>
js:
app.directive('mydirective', function () { return { link: function (scope, element, attrs) { element.bind('click', function (e) { var clickedelement = e.target; console.log(clickedelement); console.log(clickedelement.id); }); } } });
Comments
Post a Comment