我正在为项目使用ng2-dragula,并且对我来说效果很好。但是现在我想在将数据放入包中的同时传递数据。
我在互联网上搜索后发现dragulaModel
,但是当我尝试使用它时,我的代码无法正常工作。
我已经在模板中完成了以下操作:
<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>
在我的组件中:
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
});
但我收到此错误:
EXCEPTION: TypeError: Cannot read property '1' of undefined
最佳答案
此错误消息显示元素从具有指定模型的袋子“ A”掉落到没有模型的袋子“ B”中的时间。您需要为要放置元素的包“ B”指定“ dragulaModel”。
例:
<div [dragula]='"bag-a"' [dragulaModel]='records' >
...
</div>
<div [dragula]='"bag-b"' [dragulaModel]='records' >
..
</div>
关于javascript - ng2-dragula的dragulaModel无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37410060/