admin管理员组文章数量:1319025
I want access to parent element from ng-click
event's target element and remove it.
I looked some pages and angular docs and found something like below but this is not worked for me.
My Template:
<div class="element-which-i-want-access">
<span>
<button ng-click="remove(myModelObjectInCurrentScope, $event)" class="btn btn-sm btn-danger"><i class="fa fa-trash"></i></button>
</span>
</div>
My Controller:
$scope.remove = function(object, $event) {
var el = $event.target; // this meaning as clicked <button> element
var myTargetElement = el.parent().parent(); // this not working
myTargetElement.remove(); // i couldn't tried this step but i couldn't got parent element yet
}
How can I do this? Thanks in advance.
I want access to parent element from ng-click
event's target element and remove it.
I looked some pages and angular docs and found something like below but this is not worked for me.
My Template:
<div class="element-which-i-want-access">
<span>
<button ng-click="remove(myModelObjectInCurrentScope, $event)" class="btn btn-sm btn-danger"><i class="fa fa-trash"></i></button>
</span>
</div>
My Controller:
$scope.remove = function(object, $event) {
var el = $event.target; // this meaning as clicked <button> element
var myTargetElement = el.parent().parent(); // this not working
myTargetElement.remove(); // i couldn't tried this step but i couldn't got parent element yet
}
How can I do this? Thanks in advance.
Share Improve this question edited Dec 28, 2020 at 12:38 Furkan Başaran asked Oct 31, 2015 at 11:21 Furkan BaşaranFurkan Başaran 1,9472 gold badges19 silver badges28 bronze badges 02 Answers
Reset to default 4$event.target
will give the DOM element. To use parent()
on it, it need to be wrapped as follow
angular.element(el).parent().parent();
accepted answer did'nt work for me. but this code did:
var elem= angular.element($event.currentTarget);
var parent = elem.parent().parent();
parent.remove();
本文标签: javascriptHow to access parent element and remove it with angularJsStack Overflow
版权声明:本文标题:javascript - How to access parent element and remove it with angularJs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742051279a2418074.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论