获得$这angularjs [英] Get the $this in angularjs
问题描述
下面是我的问题。
HTML结构:
<tr><td><a ng-click=aClick()>Click Me</a></td></tr>
我不能与任何相关的ID /类以及
I cannot have any id/class associated with the and
我需要的是对的点击点击我,在&LT; TR&GT;
获取隐藏。我需要一个jQuery的解决方案。一些如何我无法使用 $(本)
。
What I require is that on the click of 'Click Me', the <tr>
gets hidden. I need a jQuery solution. Some how I am not able to use $(this)
.
功能:
$scope.aClick = function() {
$(this).parent().parent().css('display','block');
};
不过,这一说法给我一个错误。
But this statement gives me an error.
推荐答案
请注意:我不建议在使用控制器的DOM操作,你可以写一个指令,要做到这一点。这就是说,你可以使用 $事件
来获取事件对象,从中可以获取事件的目标,并与jQuery使用它。
Note: I wouldn't recommend using dom manipulation in a controller, you can write a directive to do this. That said you can use the $event
to get the event object, from which you can get the event target and use it with jquery.
<tr><td><a ng-click="aClick($event)">Click Me</a></td></tr>
和
$scope.aClick = function(event) {
$(event.target).parent().parent().css('display','none');
};
演示: Plunker
更新
一个更合适的角度解决方案将是使用NG隐藏
Update
A more appropriate angular solution will be is to use ng-hide
<tr ng-hide="hideRow"><td><a ng-click="hideRow = true">Click Me</a></td></tr>
演示: Plunker
这篇关于获得$这angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!