我有一个功能
transferDataSuccess(event, cat,label ,e ){
var target = e.target || e.srcElement || e.currentTarget;
this.handler.emit( {e:event, cat:cat , labelCS:event.dragData.labelCS} );
this.unhighlightElement( event , e );
}
它通过
绑定到元素(onDropSuccess)="transferDataSuccess($event, node.id , node.label , $event)"
然而它总是导致错误
TypeError: Cannot read property 'nodeName' of undefined
它无法访问event.target,angular2是否有event.target或simmiliar方法?如果我的代码没有问题?为什么它找不到event.target?
//取消强光功能
unhighlightElement( e , x ){
e=e||window.event;
var el = x || e.target;
//alert(el.nodeName)
while( el.nodeName != 'DIV'){
el = el.parentNode;
}
el.style.border="";
e.stopPropagation();
e.preventDefault();
}
答案 0 :(得分:1)
我想它应该是:
(onDropSuccess)="transferDataSuccess($event, node.id, node.label)"
,您的功能将如下所示:
transferDataSuccess(event, cat, label){
this.handler.emit({ e:event, cat:cat, labelCS: event.dragData.labelCS });
this.unhighlightElement(event.mouseEvent);
}
unhighlightElement(e){
var el = e.target;
//alert(el.nodeName)
while( el.nodeName != 'DIV'){
el = el.parentNode;
}
el.style.border="";
e.stopPropagation();
e.preventDefault();
}