gpt4 book ai didi

angular - 在 ng2-dragula 中询问删除确认

转载 作者:太空狗 更新时间:2023-10-29 19:33:35 25 4
gpt4 key购买 nike

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

目前我启用了removeOnSpill: true,因此当用户将项目拖出容器时,项目将在没有确认的情况下被删除。

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

最佳答案

你应该订阅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();
}
}

关于angular - 在 ng2-dragula 中询问删除确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48396645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com