0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AngularでDrag&Dropの実装

Last updated at Posted at 2021-05-09

記載日:2021/5/9
AngularでのDrag&Dropの実装について、忘れないように記載します。

目的

 AngularでDrag&Dropを実装する。

環境

 Angular:11.2.13
 Angular CLI:11.2.12
 Node js:10.19.0
 OS:Ubuntu

目次

 1.シンプルなDrag&Drop
 2.入替の起こるDrag&Drop

作業

1.シンプルなDrag&Drop

※スマホ非対応
・Drag&Dropしたいエレメントに対して、draggableプロパティを有効化。(html)
  draggable="true"
・Drag&Dropしたいエレメントに対して、dragstartやdragendなどの使いたいdragdropイベントを記載。(html)
・上記dragdropイベントで発火するメソッドを記載。(typescript)

ソースコードはこちら
動きの確認はこちら

2.入替の起こるDrag&Drop

※スマホ非対応
「1.シンプルなDrag&Drop」に、以下を追加。
・Drag&Dropしたいエレメントの操作性を高めるために、styleにdisplay: block;を記載。(html)
・入替を起こすために、
  dragstartメソッドで、ドラッグしたエレメント情報を取得。
  dropメソッドで、ドロップエリアのエレメント情報を取得。その後、2つのエレメント情報をもとに、配列の入替を実施。

ソースコードはこちら
動きの確認はこちら

参考にさせて頂いたサイト

https://developer.mozilla.org/ja/docs/Web/API/HTML_Drag_and_Drop_API/Drag_operations
https://developer.mozilla.org/ja/docs/Web/API/HTML_Drag_and_Drop_API

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?