Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created September 3, 2021 18:41
Show Gist options
  • Save NyaGarcia/708a3dac79551155062465057d7a46b8 to your computer and use it in GitHub Desktop.
Save NyaGarcia/708a3dac79551155062465057d7a46b8 to your computer and use it in GitHub Desktop.
Adding drop method
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-todo-list',
templateUrl: './todo-list.component.html',
styleUrls: ['./todo-list.component.css'],
})
export class TodoListComponent implements OnInit {
constructor() {}
ngOnInit(): void {}
todos = [
'Refactor code',
'Eat pizza',
'Fix bugs',
'Update kernel',
'Eat more pizza',
'Fix more bugs',
];
drop(event: CdkDragDrop<string[]>) {
moveItemInArray(this.todos, event.previousIndex, event.currentIndex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment