ng2draggable
ng2draggable copied to clipboard
The draggable handle not working if it contains nested elements
Hello. I suggest to use the following code:
@HostListener('mousedown', ['$event'])
onMouseDown(event:MouseEvent) {
if(event.button === 2)
return; // prevents right click drag, remove his if you don't want it
// search the handle in parent elements
if (this._handle !== undefined) {
let node = event.target;
while(true) {
if ( ! node || node === this._handle)
break;
node = node['parentNode'];
}
if ( ! node)
return;
}
this.md = true;
this.topStart = event.clientY - this.element.nativeElement.style.top.replace('px','');
this.leftStart = event.clientX - this.element.nativeElement.style.left.replace('px','');
}
I could make a fork but I could not find the repository in github, I suppose the repository is in npmjs. Please update your repository, if the code is normal.
Thanks for this alhimik1986, that code snippet works like a charm!