angularng2-dragula

ng2-dnd how use class css when drag dragOver dropOver for angular2


http://akserg.github.io/ng2-webpack-demo/#/dnd this is a demo for this drag&drop using angular2 so how can I affect my class css to indicate that this zone is the droppable zone

enter image description here

this is a part of code from github source project

 _onDragEnterCallback(event: MouseEvent) {
     if (this._dragDropService.isDragged) {
         this._elem.classList.add(this._config.onDragEnterClass);
         this.onDragEnter.emit({dragData: this._dragDropService.dragData, mouseEvent: event});
     }
 }

how can I affect my class to this line this._elem.classList.add(this._config.onDragEnterClass);


Solution

  • You can see it emits onDragEnter event so you need to subscribe to it.

    For example:

    <div dnd-draggable
        [dragEnabled]="true"
        [dropZones]="['zone1']"
        (onDragEnter)="myEventHandler($event)">
    

    Then inside myEventHandler() you can do whatever you want.

    By the way, you could also use something like this without any extra methods:

    <div dnd-draggable
        [class.highlighted]="highlightMe"
        [dragEnabled]="true"
        [dropZones]="['zone1']"
        (onDragEnter)="highlightMe=true"
        (onDragLeave)="highlightMe=false">