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);       });     }   } }); 

demo: http://plnkr.co/edit/eevnmfu2ybj3qqrraezh?p=preview


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -