Search code examples
angularng2-dragula

Angular2 : ng2-dragula - nested dragula


I have a requirement to use nested ng-dragula in AngularJS 2 for the below nested student list items.

Student 1 book1 book2 book3

Student 2 book4 book5 book6

Student 3 book7 book8 book9

I have to drag and drop Student position, which i am able to do it with the below code.

<div [dragula]='"student-bag"' [dragulaModel]='studentList'>
     <div class="row" *ngFor="let student of studentList; let stud = index">
        ...
     </div>
</div>

I have to drag & drop the books with in student as well as between students. Something like below.

Student 1 book1 book3 book2

Student 2 book4 book5

Student 3 book7 book6 book8 book9

I tried the below code

<div [dragula]='"student-bag"' [dragulaModel]='studentList'>
     <div class="row" *ngFor="let student of studentList; let stud = index">
        ...
        <div [dragula]='"book-bag"' [dragulaModel]='student.books'>
             <div class="row" *ngFor="let book of student.books; let bk= index">
              ....
             </div>
        </div>
     </div>
</div>

however book item is not draggable either within student or between students. please suggest.


Solution

  • Just had the same question. The answer lies in move. See https://github.com/bevacqua/dragula/issues/31

      var drake_books = dragula({
        isContainer: function (el) {
          return el.classList.contains('student');
        },
        moves: function(el, container, target) {
          return target.classList.contains('book');
        }
      });