Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couldn't able to pass the anchor tag id value through ng-click in Angular JS. Getting undefined value

I'm a newbie in AngularJS please help me out to find the issue , code shown below ( html code part - 1 with js code part-2) is working perfectly in my browser and I'm getting the alert.

Html Code

<a  id={{data.id}} ng-click='onclickof("data")' class="item item-icon-left" >

               {{data.name}} + {{data.id}}
</a>

Function defined on controller

$scope.onclickof= function(idinput){
  alert(idinput);
  }

But when I tried to pass the anchor tag id to my function its giving alert with 'undefined' string. Please check the code below.

Html code which passing id of anchor tag.

<a  id={{data.id}} ng-click='onclickof(this.id)' class="item item-icon-left" >

                {{data.name}} + {{data.id}}
  </a>

Can anyone help me to find out the issue . Thanks in advance... :)

like image 201
Nithin CV Avatar asked Nov 22 '25 08:11

Nithin CV


1 Answers

Just try ng-click='onclickof(data.id)'

You can also use your first example but without quotes like ng-click='onclickof(data)'

like image 73
Dalorzo Avatar answered Nov 24 '25 20:11

Dalorzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!