1

I am trying to get info from the ng-click element. When I log $event from clicked element I get the right info but when I click the child element of then I get the info about the child and not the parent where the ng-click is set. Here is the fiddle link

http://jsfiddle.net/g3x2ndyc/5/.

var app = angular.module('app',[])
app.controller('appCtr', function($scope) {
$scope.testThis = function(evt){
  //evt.stopPropagation();
 // evt.preventDefault();
console.log(evt.srcElement.offsetLeft)
console.log(evt.srcElement.offsetWidth)
console.log('____________________________')
}
});
4
  • What info do you want? Do you mean the parent $scope? Commented Sep 15, 2014 at 18:55
  • Another thing you can do, is add pointer-events:none; to the CSS of your inner-div; you will then only see mouse events for the div that has the ng-click Commented Sep 15, 2014 at 20:02
  • Thats NICE. Thanks Darren Commented Sep 16, 2014 at 0:45
  • UPDATED - But didn't work in Firefox evt.srcElement is undefined Commented Sep 16, 2014 at 1:26

2 Answers 2

1

use evt.currentTarget not evt.srcElement (that one is mainly for IE).

Look at fiddle http://jsfiddle.net/g3x2ndyc/11/

var app = angular.module('app',[])
app.controller('appCtr', function($scope) {
    $scope.testThis = function(evt){
        console.log(evt.currentTarget.offsetLeft)
        console.log(evt.currentTarget.offsetWidth)
        console.log('____________________________')
}
});
Sign up to request clarification or add additional context in comments.

Comments

0

Hard to tell exactly what you are ultimately trying to do, but you can just pass the id in to the click event then grab the position based on that.

ng-click="myevent('idName')

myevent(id) {
  jquery('#'+id).position();
}

2 Comments

I trying to get the position of element which I am clicking. Here is the jsfiddle link jsfiddle.net/g3x2ndyc/5.
This worked thank you, but I had to add Jquery. There should be some way with Angular.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.