akserg / ng2-dnd

Angular 2 Drag-and-Drop without dependencies
MIT License
838 stars 251 forks source link

Tree component dragging child node to parent is not working #211

Open OscarWozniak opened 7 years ago

OscarWozniak commented 7 years ago

Quick ilustration (A, B - components):

1 Drag B

2 Put it on A

3 console.log data from component - Data will be always not from dragged comp

Below is my quick code:

Tree.html

<div style="background-color: blue;"
  dnd-draggable [dragEnabled]="true" [dragData]="tree"

>

  <p dnd-droppable (onDropSuccess)="say($event, tree, hec())" style="background-color: red;">{{tree.title}}</p>
  <div *ngIf="tree.tree">
    <app-tree [tree]="tree.tree"></app-tree>
  </div>

</div>

tree.ts

@Component({
  selector: 'app-tree',
  templateUrl: './tree.html',
  styleUrls: ['./page-not-found-error.component.scss']
})
export class TreeComponent implements OnInit {

  @Output()
  @Input()
  tree;

  hec(){
    return this;
  }

  say(e, tri, lol){
    console.log(1, e);
    console.log(2, this.tree);
    console.log(3, tri);
    console.log(4, lol);
  }

  constructor() {
  }

  ngOnInit() {
  }

}

Parent component

@Component({
  selector: 'app-page-not-found-error',
  templateUrl: './page-not-found-error.component.html',
  styleUrls: ['./page-not-found-error.component.scss']
})
export class PageNotFoundErrorComponent implements OnInit {

  someTree = {
    title: '1',
    tree: {
      title: '2',
      tree: {
        title: '3',

      }
    }
  };

  constructor() {
  }

  ngOnInit() {
  }

}

html of parent component

<app-tree [tree]="someTree"></app-tree> All what I want is to put data from node to node parent.