Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag & drop between two lists in different components #73

Closed
f-jiang opened this issue Dec 10, 2017 · 3 comments
Closed

Drag & drop between two lists in different components #73

f-jiang opened this issue Dec 10, 2017 · 3 comments

Comments

@f-jiang
Copy link

f-jiang commented Dec 10, 2017

Is it possible for drag & drop to work when each list is contained within its own component?

I currently have code like the following. On a visual level, drag & drop works (except that items transferred between lists don't show up until a second item is transferred), but the items arrays' actual contents don't change.

Parent component:

import { Component, OnInit } from '@angular/core';
import { ItemsService } from '../items.service';

@Component({
  selector: 'app-multi-list',
  template: `
<h2>Drag / drop the item</h2>
<h3>list 1</h3>
<app-list [(items)]="itemsService.items1"></app-list>
<h3>list 2</h3>
<app-list [(items)]="itemsService.items2"></app-list>

<hr>

<h2>See the result</h2>
<div>
  <h3>list 1</h3>
  <div *ngFor="let item of itemsService.items1">{{ item }}</div>
  <h3>list 2</h3>
  <div *ngFor="let item of itemsService.items2">{{ item }}</div>
</div>
`,
  styleUrls: ['./multi-list.component.css']
})
export class MultiListComponent implements OnInit {

  constructor(public itemsService: ItemsService) { }

  ngOnInit() { }

}

Child component that contains a sortable list:

import { Component, Input, OnInit } from '@angular/core';
import { SortablejsOptions } from 'angular-sortablejs';

@Component({
  selector: 'app-list',
  template: `
<div [sortablejs]="items" [sortablejsOptions]="{ group: 'test' }">
  <div *ngFor="let item of items">{{ item }}</div>
</div>
`,
  styleUrls: ['./list.component.css']
})
export class ListComponent implements OnInit {

  @Input() items: any[];

  ngOnInit() { }

}
@smnbbrv
Copy link
Member

smnbbrv commented Dec 11, 2017

Hi @f-jiang

could you reproduce it, please, within a fork of a demo project?

@smnbbrv
Copy link
Member

smnbbrv commented Dec 11, 2017

Hi @f-jiang

the issue is fixed in @2.4.0, enjoy :)

@smnbbrv smnbbrv closed this as completed Dec 11, 2017
@fujale
Copy link

fujale commented Jan 31, 2019

Could you please let me know how can we drag and drop items from left component to right component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants