我希望从ng-click
事件的目标元素访问父元素并将其删除。
我查看了一些页面和角度文档并找到了类似下面的内容,但这对我不起作用。
我的模板:
<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>
我的控制器:
$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
}
我该怎么做?提前谢谢。
答案 0 :(得分:4)
interface Column<T>{
/**
* extracts valu from the column
*
* @return the value
*/
T value() throws SQLException;
}
public class test{
public void doExtraction() throws SQLException {
Collection<Column<?>> cols = getColumns(); //Returns the collection of Column<T>.
for(Column c : cols){
put(c, c.value());
}
}
public <T> void put(Column<T> c, T o){
//put the extracted value in another place
}
}
将提供DOM元素。要在其上使用$event.target
,需要将其打包为
parent()
答案 1 :(得分:0)
接受的答案对我没有用。但是这段代码确实做到了:
var elem= angular.element($event.currentTarget);
var parent = elem.parent().parent();
parent.remove();