[英]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. 我是AngularJS的新手,请帮我找到问题,下面显示的代码(html代码部分 - 1与js代码第2部分)在我的浏览器中完美运行,我收到警报。
Html Code Html代码
<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. 但是当我尝试将锚标记id传递给我的函数时,它会使用' undefined '字符串发出警报。 Please check the code below.
请检查以下代码。
Html code which passing id of anchor tag. 传递锚标记的id的Html代码。
<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)'
试试
ng-click='onclickof(data.id)'
You can also use your first example but without quotes like ng-click='onclickof(data)'
你也可以使用你的第一个例子,但没有像
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. 'this.id'不起作用,因为它不在$ scope范围内。
For more information regarding this please check: 有关这方面的更多信息,请检查:
https://docs.angularjs.org/guide/scope https://docs.angularjs.org/guide/scope
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.