在ng2-dragula中询问删除确认

问题描述 投票:3回答:1

我在Angular5应用程序中使用ng2-dragula。我需要在删除项目之前获得用户的确认。

目前我已启用removeOnSpill: true,因此当用户将项目拖出容器时,该项目将被删除而不进行确认。

removeOnSpill: true的情况下如何实现要求确认删除。

angular typescript drag-and-drop ng2-dragula
1个回答
0
投票

您应该订阅drop事件,当它在容器外部时,您可以在回调中请求确认。

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();
   }
 }
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.