ng2-dragula setOptions和删除版本问题 [英] ng2-dragula setOptions and drop version problem

查看:156
本文介绍了ng2-dragula setOptions和删除版本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然1.5.0支持 this.dragulaService.setOptions ,而2.1.1则不支持,反之,而2.1.1支持 this.dragulaService.drop 订阅1.5.0不.

Apparently 1.5.0 support this.dragulaService.setOptions while 2.1.1 doesn't and in reverse while 2.1.1 support this.dragulaService.drop subscribe 1.5.0 doesn't.

Stackblitz Fork for 1.5.0

Stackblitz Fork for 2.1.1

要注意的相关代码:

1.5.0(不起作用)

1.5.0 (not working)

(错误):

无法调用类型缺少调用签名的表达式.类型"EvenEmitter"没有兼容的呼叫签名.(财产)AppComponent.dragulaService:DragulaService

Cannot invoke an expression whose type lacks a call signature. Type 'EvenEmitter' has no compatible call signatures. (property) AppComponent.dragulaService: DragulaService

this.dragulaService.drop("dnd")
      .subscribe(({ name, el, target, source, sibling }) => {
      //content
}

1.5.0(正在运行)

1.5.0 (working)

this.dragulaService.setOptions('dnd', {
  moves: (el, source, handle, sibling) => !el.classList.contains('nodrag')
});

2.1.1(正常工作)

2.1.1 (working)

this.dragulaService.drop("dnd")
    .subscribe(({ name, el, target, source, sibling }) => {
    //content
}

2.1.1(不起作用)

2.1.1 (not working)

this.dragulaService.createGroup("dnd", {
  moves: (el, source, handle, sibling) => !el.classList.contains('nodrag')
});

(错误):

'{moves:(el:any,source:any,handle:any,sibling:任何)=>布尔值;}'不能分配给类型的参数'DragulaOptions'.对象文字只能指定已知属性,并且拖动选项"类型中不存在动作".(参数)句柄:任意

Argument of type '{moves: (el: any, source: any, handle: any, sibling: any) => boolean; }' is not assignable to parameter of type 'DragulaOptions'. Object literal may only specify known properties, and 'moves' does not exist in type 'Dragula Options'. (parameter) handle: any

请注意,虽然有迁移指南更改日志它确实如何将setOptions替换为创建组.但对于我来说仍然无法正常工作.

Note while there is a migration guide and changelog it does state how to replace the setOptions into create group. But it's still not working in my case.

有什么办法可以同时使用这两个功能?还是我想念一些明显的东西?

Is there any way to use both functions? Or do I miss something obvious?

推荐答案

是否要:创建组&一起使用放置功能?

Do you want: create group & use drop functionality together?

我们将 createGroup drop 一起使用,但有一个小的区别但又有小的区别-在Subscription中添加了drop服务,但我认为这没有任何关系.所以我们的代码是hire:

We use createGroup together with drop but with one small difference but with small difference - drop services is added inside Subscription, but I don't think this has any matters. So our code is hire:

export class xxxComponent implements OnInit {
    ...
    public dragula$: Subscription
    ...

    constructor(public dragulaService: DragulaService) {

        this.dragulaService.createGroup('ITEMS', {
            direction: 'vertical',
            moves: (el, source, handle): boolean => handle.className.indexOf('item-keeper') > -1
        });
    }

    ngOnInit() {

        this.dragula$.add(this.dragulaService.drop('ITEMS')
            .subscribe(({name, el}) => {
                ....
            })
        );
    }

}

我认为根据有关事件的文档,我们的解决方案是正确的: https://github.com/valor-software/ng2-dragula#events

I think that our solutions is correct in according with documentation about events: https://github.com/valor-software/ng2-dragula#events

最后,我认为您的问题是类名错误,因为其他所有内容都可以在您的Stackblitz示例中正常运行.如果您取消评论:

Finally I think that your problem is an error with class name because everything others work perfectly on you Stackblitz example. If you uncomment:

    this.dragulaService.createGroup("dnd", {
      moves: (el, source, handle, sibling) => !el.classList.contains('nodrag')
    });

您的标签不可拖动,因此您可以找到所需的东西.

your labels is not draggable so you get what you need.

这篇关于ng2-dragula setOptions和删除版本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆