ng2-dragula
ng2-dragula copied to clipboard
On use DragulaModel TypeError: Cannot read property 'slice' of undefined
REQUIRED: Before filing a usage question
Change each [ ]
to [x]
when you have done it.
- [x] My issue title starts with
Cannot read property 'slice' of undefined
- [x] I have read the README, especially the 'classic blunders' section
- [x] I have looked at the demos to see if my use case has obvious examples.
- [x] I have searched the
ng2-dragula
issues, including closed issues. - [x] I have browsed the issues labeled "future reference" for problems that have been solved before.
When I want to use dragulaModel to update and list of data i get "TypeError: Cannot read property 'slice' of undefined " from dragula.js.
this is matrix of cells where i want to insert the dragged items:
<ul class="RACI-cell-container"
[dragula]='"RACI-drag"'
*ngFor="let row of column.Items; let rIndex = index"
[id]="column.PersonId+'/'+row.ItemId"
[(dragulaModel)]='column.Value'
>
<li class="dragable-RACI-symbol"
[ngStyle]="{'background-color': RACIcolors[symbol] }"
*ngFor="let symbol of row.Value; let sIndex = index">
{{symbol}}
</li>
</ul>
```
`
this is the items container
```
<ul class="drag-cell-container clearfix"
[dragula]='"RACI-drag"'
[dragulaModel]="RACIsymbols"
id="RACI-bag" >
<li class="dragable-RACI-symbol"
[ngStyle]="{'background-color': RACIcolors[symbol] }"
*ngFor="let symbol of RACIsymbols; let i = index">
{{symbol}}
</li>
</ul>
```
this is where I set options in .ts
`this.dragulaService.createGroup('RACI-drag', {
copy: (el, source) => {
return source.id === 'RACI-bag';
},
copyItem: (item) => ({
...item
}),
moves: function (el, container, handle) {
return container.id == 'RACI-bag' ;
},
accepts: function (el, target, source, sibling) {
if(target.id == source.id)
return false;
return true
},
revertOnSpill: true
})`
This is Matrix structure
`RACImatrix =
[
{
PersonId: 1,
Items:
[
{
ItemId: 1,
Value: [] // <= here i want to insert what i have dragged
}
],
},
];`
This looks like your problem. You're giving ng2-dragula undefined at some point. Often this is just uninitialized data.