我正在为我的项目使用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
答案 0 :(得分:2)
此错误消息显示元素从包&#34; A&#34;将指定的型号装入袋子&#34; B&#34;没有模特。你需要指定&#34; dragulaModel&#34;包包&#34; B&#34;你试图放弃元素。
示例:
<div [dragula]='"bag-a"' [dragulaModel]='records' >
...
</div>
<div [dragula]='"bag-b"' [dragulaModel]='records' >
..
</div>
&#13;