Search code examples
typescriptdragula

Dragula: get class and id of the dragged item


I have seen this, but it does not work in my code. I am using Dragula, in my Angular2 application with Typescript.

I need to get the id of the element of the draged element. Here is a part of the typescript class:

 constructor(private dragulaService: DragulaService) {

    dragulaService.drop.subscribe((value) => {
       this.onDrop(value.slice(1));
    });

  }


  private onDrop(args) {
    let [e, el] = args;
    console.log("on Drop");
    console.log(e);
    console.log(el);
  }

I know the el contains the draged element, but how can i get the id out of an html element in typescript?


Solution

  • If el is the dragged element, then its id is el.id. That's how the DOM works. If you are dragging an element <div id="foo">something</div> and this element is assigned to el in your code, then el.id will be "foo".