简体   繁体   English

ng2-dragula的dragulaModel无法正常工作

[英]dragulaModel of ng2-dragula is not working

I am using ng2-dragula for my project andd it worked well for me.but now I want to pass data while dropping an element in the bag. 我正在为项目使用ng2-dragula并且对我来说效果很好。但是现在我想在将数据放入包中的同时传递数据。

I searched on internet and found dragulaModel but when I am trying to use it it my code its not working. 我在互联网上搜索并找到dragulaModel但是当我尝试使用它时,我的代码无法正常工作。 I have done the following in my template: 我已经在模板中完成了以下操作:

<li *ngFor="#comp of record.components | search:searchComp:true" [dragula]='"row-bag"' [dragulaModel]='record.components'>
    <p class="text-center h6" style="font-size:8px;color:blue;font-weight:bold;"> {{comp.name }}</p>                                
</li>

and in my component : 在我的组件中:

 dragulaService.dropModel.subscribe((value:any[]) => {
        console.log(value);
        this.dragulaService.onDropModel(value.slice(1));
    });
    dragulaService.removeModel.subscribe((value:any[]) => {
        console.log(value);
        this.dragulaService.onRemoveModel(value.slice(1));
    });
    dragulaService.drag.subscribe((value: any[]) => {
        //console.log(`drag: ${value[0]}`);
        this.onDrag(value.slice(1));
    });
    dragulaService.drop.subscribe((value: any[]) => {
        //console.log(`drop: ${value[0]}`);
        this.onDrop(value.slice(1));           
    });
    dragulaService.over.subscribe((value: any[]) => {
        //console.log(`over: ${value[0]}`);
        this.onOver(value.slice(1));
    });
    dragulaService.out.subscribe((value: any[]) => {
        //console.log(`out: ${value[0]}`);
        this.onOut(value.slice(1));
    });
    dragulaService.setOptions('row-bag', {
        copy: true
    });

but I am getting this error: 但我收到此错误:

EXCEPTION: TypeError: Cannot read property '1' of undefined

This error message showing when element dropped from bag "A" with specified model in to bag "B" without model. 此错误消息显示元素从具有指定模型的袋子“ A”掉落到没有模型的袋子“ B”中的时间。 You need to specify the "dragulaModel" for bag "B" in which you trying to drop the element. 您需要为要放置元素的包“ B”指定“ dragulaModel”。

Example: 例:

 <div [dragula]='"bag-a"' [dragulaModel]='records' > ... </div> <div [dragula]='"bag-b"' [dragulaModel]='records' > .. </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM