You just need to create a drop method in the service and call that drop method from two components. And have to wrap these two components with cdkDropListGroup on the parent component.
App Component
<div class="wrapper">
<div cdkDropListGroup>
<app-test1></app-test1>
<app-test2></app-test2>
</div>
</div>
Test1 Component
<div class="container">
<h2>Movies</h2>
<div cdkDropList [cdkDropListData]="MoviesList"
class="movie-list" (cdkDropListDropped)="onDrop($event)">
<div class="movie-block" *ngFor="let moviesList of MoviesList" cdkDrag>{{moviesList}}</div>
</div>
</div>
export class Test1Component implements OnInit {
constructor(private ss: ShareService) { }
ngOnInit() {
}
// Transfer Items Between Lists
MoviesList = [
'The Far Side of the World',
'Morituri',
'Napoleon Dynamite',
'Pulp Fiction',
'Blade Runner',
'Cool Hand Luke',
'Heat',
'Juice'
];
onDrop(event: CdkDragDrop<string[]>) {
this.ss.drop(event);
}
}
Test2 Component
<div class="container">
<h2>Movies Watched</h2>
<div cdkDropList [cdkDropListData]="MoviesWatched"
[cdkDropListConnectedTo]="list-1" class="movie-list" (cdkDropListDropped)="onDrop($event)">
<div class="movie-block" *ngFor="let moviesWatched of MoviesWatched" cdkDrag>{{moviesWatched}}</div>
</div>
</div>
import { Component, OnInit } from '@angular/core';
import { CdkDragDrop } from '@angular/cdk/drag-drop';
import { ShareService } from '../share.service';
@Component({
selector: 'app-test2',
templateUrl: './test2.component.html',
styleUrls: ['./test2.component.css']
})
export class Test2Component implements OnInit {
constructor(private ss: ShareService) { }
MoviesWatched = [
'Transformers'
];
ngOnInit() {
}
onDrop(event: CdkDragDrop<string[]>) {
this.ss.drop(event);
}
}
ShareService
import { Injectable } from '@angular/core';
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
@Injectable()
export class ShareService {
constructor() { }
public drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex);
}
}
}
Here is the working link