获取元素的属性,NG-点击功能angularjs [英] Getting attribute of element in ng-click function in angularjs
本文介绍了获取元素的属性,NG-点击功能angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像下面这称之为点击时在控制器中的功能span标记。
I have a span tag like below which call a function in the controller when clicked.
HTML
<div class="row" ng-repeat="event in events">
<div class="col-lg-1 text-center">
<span class="glyphicon glyphicon-trash" data={{event.id}} ng-click="deleteEvent()">
</span>
</div>
</div>
控制器
$scope.deleteEvent=function(){
console.log(this);
}
我需要在控制器的功能数据属性的值。我试着用这个关键字和$事件;没有一个工作。
I need to get the value in data attribute in the controller function. I tried using this keyword and $event; neither one worked.
请帮忙。
推荐答案
尝试其直接传递到NG-点击功能:
Try passing it directly to the ng-click function:
<div class="col-lg-1 text-center">
<span class="glyphicon glyphicon-trash" data="{{event.id}}"
ng-click="deleteEvent(event.id)"></span>
</div>
然后,它应该可以在您的处理程序:
Then it should be available in your handler:
$scope.deleteEvent=function(idPassedFromNgClick){
console.log(idPassedFromNgClick);
}
这篇关于获取元素的属性,NG-点击功能angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文