How to create a To-Do list using Drag and Drop in Angular 7 ? Last Updated : 14 May, 2020 Comments Improve Suggest changes 5 Likes Like Report We can easily create a To-Do list using Drag-Drop module provided by angular Component Development Kit (CDK). First of all, create an angular component by using the following command- ng g c To-Do Now import CdkDragDrop, moveItemInArray, transferArrayItem from @angular/cdk/drag-drop to our to-Do component, Writing the code for component view: Create two divisions, one for the items that are TO BE DONE and other for items that are COMPLETED. These are some of theparameters: cdkDropList: It lets the division know that it is a drop container cdkDropListData: It binds the data to the view cdkDropListConnectedTo: It gets the id of another drop container that the current division is connected to cdkDropListDropped: After dragging the items, the data model has to be updated. For that, we can listen to this event cdkDrag: it specifies that the item can be dragged Example: html <div> <!-- container for both list --> <h1>To do</h1> <!-- To-Do list --> <div cdkDropList #todoList="cdkDropList" [cdkDropListConnectedTo]="[doneList]" [cdkDropListData]="todo" (cdkDropListDropped)="drag($event)"> <div *ngFor="let item of todo" cdkDrag>{{item}}</div> </div> </div> <div> <h1>Done</h1> <!-- Done list --> <div cdkDropList #doneList="cdkDropList" [cdkDropListConnectedTo]="[todoList]" [cdkDropListData]="done" class="example-list" (cdkDropListDropped)="drag($event)"> <div *ngFor="let item of done" cdkDrag>{{item}}</div> </div> </div> Now write the code for listening the event and adding the data. Here we used a hardcoded list but you can always take input by using ngmodel directive. There are two possibilities: Item is dragged to the same container: Use moveItemInArray to move it in the same container Item is dragged to another container: Use transferArrayItem to move to another container javascript export class To-Do { // hardcoded lists todo = [ 'Go to gym', 'Eat lunch', 'Take a nap', 'Physics syllabus' ]; done = [ 'Assignment', 'Coding practice', 'Maths syllabus', 'English syllabus' ]; //function for listening to the event drag(event: CdkDragDrop<string[]>) { //if movement if within the same container if (event.previousContainer === event.container) { moveItemInArray( event.container.data, event.previousIndex, event.currentIndex); } //if movement if to other containers else { transferArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex); } } } Output: successful Dragging of 'Eat lunch' from To do list to done list. Create Quiz Comment V vaibhav19verma Follow 5 Improve V vaibhav19verma Follow 5 Improve Article Tags : Web Technologies AngularJS AngularJS-Misc Explore AngularJS BasicsAngularJS Tutorial 5 min read Introduction to AngularJS 4 min read Angular CLI | Angular Project Setup 3 min read AngularJS Expressions 2 min read AngularJS Modules 3 min read AngularJS ng-model Directive 4 min read AngularJS Data Binding 4 min read AngularJS Controllers 3 min read AngularJS | Scope 2 min read AngularJS Services 4 min read AngularJS | AJAX - $http 3 min read AngularJS | Tables 2 min read AngularJS Select Boxes 2 min read AngularJS SQL 3 min read AngularJS HTML DOM 2 min read AngularJS Events 3 min read AngularJS | Forms 3 min read AngularJS Form Validation 3 min read AngularJS | API 2 min read AngularJS and W3.CSS 2 min read AngularJS Includes 3 min read AngularJS Animations 1 min read AngularJS | Application 3 min read AngularJS DirectivesAngularJS Directives 9 min read AngularJS ng-app Directive 1 min read AngularJS ng-bind Directive 2 min read AngularJS ng-bind-html Directive 2 min read AngularJS ng-bind-template Directive 2 min read AngularJS ng-blur Directive 1 min read AngularJS ng-change Directive 2 min read AngularJS ng-checked Directive 2 min read AngularJS ng-class Directive 2 min read AngularJS ng-class-even Directive 2 min read AngularJS ng-class-odd Directive 2 min read AngularJS ng-click Directive 2 min read AngularJS ng-cloak Directive 2 min read AngularJS ng-controller Directive 2 min read AngularJS Directives Complete Reference 2 min read AngularJS FiltersAngularJS | Filters 7 min read AngularJS currency Filter 2 min read AngularJS | date Filter 2 min read AngularJS filter Filter 3 min read AngularJS json Filter 2 min read AngularJS limitTo Filter 2 min read AngularJS lowercase Filter 1 min read AngularJS number Filter 1 min read AngularJS orderBy Filter 4 min read AngularJs uppercase Filter 1 min read AngularJS Converting FunctionsAngularJS angular.lowercase() Function 2 min read AngularJS angular.uppercase() Function 1 min read AngularJS angular.forEach() Function 1 min read AngularJS Comparing FunctionsAngularJS angular.isArray() Function 2 min read AngularJS angular.isDate() Function 2 min read AngularJS angular.isDefined() Function 2 min read AngularJS angular.isElement() Function 2 min read AngularJS angular.isFunction() Function 2 min read AngularJS angular.isNumber() Function 2 min read AngularJS angular.isObject() Function 2 min read AngularJS | angular.isString() Function 1 min read AngularJS angular.isUndefined() Function 2 min read AngularJS angular.equals() Function 2 min read AngularJS angular.toJson() Function 2 min read AngularJS QuestionsHow to bundle an Angular app for production? 4 min read How to add many functions in one ng-click directive? 2 min read How to directly update a field by using ng-click in AngularJS ? 3 min read How to Add Dynamic Options for Multiple Selects Inside ng-repeat Directive ? 3 min read How to detect when an @Input() value changes in Angular? 3 min read How to open popup using Angular and Bootstrap ? 2 min read How to reload or re-render the entire page using AngularJS? 2 min read How to add input fields dynamically on button click in AngularJS ? 2 min read How to Create Button Dynamically with Click Event in Angular ? 2 min read How to use jQuery in Angular ? 2 min read AngularJS Examples 2 min read Like