4

I have this code in the view:

<span id="l3-bridge" ng-click="redirect('l3bridge')" class="menu-opt">
    <img class="marginleft" src="/web/bundles/lima3main/images/icon-l3bridge.png">
    L3 Bridge
</span>

And this is my redirect function in angular:

$scope.redirect = function(url) {

    var element = angular.element( $(this) );
    console.log(element);

}

What i need to do is get the id value (in this case l3-bridge) from the element that i clicked.

Is there any equivalent of $(this).attr('id') from jQuery to AngularJS ?

Edit: I mean, i need the element's id of the view. How can i do it with angular?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Jhonatan Sandoval
  • 1,283
  • 6
  • 24
  • 40
  • Why not just mix in jQuery? I'm not sure about the answer to the question though, i've never needed that in any of my projects but have used the jQuery expression - they play well together, in case you weren't already aware. – Nikki Mather Jun 26 '14 at 22:17
  • 1
    @NikkiMather jQuery is rarely a good choice with angular (angular picks jqLite by default) – axelduch Jun 26 '14 at 22:20
  • Angulars jQlite is just not enough if you have to support IE8 as it doesn't support sizzle – jantimon Jun 26 '14 at 22:24
  • @aduch - how so? What's wrong with JQuery and Angular? – Christian Bonato Jun 26 '14 at 22:34
  • @Bonatoc Nothing, as I said, it is simply rarely a good choice, this could help you decide whether you need it or not. http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs-if-i-have-a-jquery-background/15012542#15012542 – axelduch Jun 26 '14 at 22:40

1 Answers1

4

Pass the $event to the handler:

<span id="l3-bridge" ng-click="redirect($event, 'l3bridge')" class="menu-opt">
    <img class="marginleft" src="/web/bundles/lima3main/images/icon-l3bridge.png">
    L3 Bridge
</span>

$scope.redirect = function(obj, url) {

    var id = obj.target.attributes.id.value;

}
cuttlas
  • 971
  • 5
  • 17