4

I am using ng2-dragula im my Angular5 application. I need to get confirmation from user before deleting an item.

Currently I have enabled removeOnSpill: true, so when the user drag out the item out of the container the item will be removed without confirmation.

How to achieve asking confirmation to delete in case of removeOnSpill: true.

Julien Rousé
  • 1,115
  • 1
  • 15
  • 30
Rosa Mystica
  • 243
  • 1
  • 3
  • 17

1 Answers1

0

You should subscribe to the drop event, and when it's outside the container, you can ask for confirmation in a callback.

import { Subscription } from 'rxjs';
import { DragulaService } from 'ng2-dragula';

export class MyComponent {
 subs = new Subscription();

 constructor(private dragulaService: DragulaService) {
   this.subs.add(this.dragulaService.drop("VAMPIRES")
     .subscribe(({ name, el, target, source, sibling }) => {
     //something like:
         if(target.className != 'container') { 
           this.dragulaService.find('container').drake.cancel(confirm(
             "Do you really want to erease me? Do you really want to wipe me out?!"))}
      })
     );
   }

   ngOnDestroy() {
   // destroy all the subscriptions at once
     this.subs.unsubscribe();
   }
 }