ng2-dragula icon indicating copy to clipboard operation
ng2-dragula copied to clipboard

On use DragulaModel TypeError: Cannot read property 'slice' of undefined

Open StefanBoacaSaulescu opened this issue 6 years ago • 1 comments

REQUIRED: Before filing a usage question

Change each [ ] to [x] when you have done it.

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
            }
        ],
      },
  ];`

StefanBoacaSaulescu avatar Nov 28 '18 11:11 StefanBoacaSaulescu

This looks like your problem. You're giving ng2-dragula undefined at some point. Often this is just uninitialized data.

cormacrelf avatar Feb 14 '19 03:02 cormacrelf