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

StackOverflow https://stackoverflow.com/questions/23563430

문제

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... :)

도움이 되었습니까?

해결책

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

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

다른 팁

Yes, you will just have to this

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

'this.id' will not work because it is not under the $scope.

For more information regarding this please check:
https://docs.angularjs.org/guide/scope

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top