首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ng2-dragula中要求确认删除

在ng2-dragula中要求确认删除
EN

Stack Overflow用户
提问于 2018-01-23 15:51:11
回答 1查看 544关注 0票数 4

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

目前我已经启用了removeOnSpill: true,所以当用户将项目拖出容器时,项目将被移除而不进行确认。

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

EN

回答 1

Stack Overflow用户

发布于 2018-09-18 20:48:26

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

代码语言:javascript
复制
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();
   }
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48396645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档