Home > database >  Angular - How to drag/drop with Dragula service based on a condition
Angular - How to drag/drop with Dragula service based on a condition

Time:10-27

Is there any way to drag only if a variable inside the typescript is true, also after drag can I call a function to save this sorting directly to DB? so far I solved auto saving after drop but I can't use two services with dragula (one to handle and the other to call for a sorting function )

I can't use both two services in the same time

this.dragulaService.createGroup('chapters-list', {
  moves: function (el, container, handle) {
    //the only way I found here is just to check if a class name exists in the html
  }
});

this.dragulaService.out('chapters-list').subscribe((value) => {
  this.updateSorting();//This works fine after drop it will update to db
});

CodePudding user response:

The only way can works is to set boolean variable in TS and in view check if this variable is true then add/remove class

 <div [ngClass]="canDrag?'':'edit-mode'">

and in Dragula createGroup add this condition

 return !handle.classList.contains('edit-mode');
  • Related