Skip to content

Commit ac681dd

Browse files
author
Your Name
committed
Angular Material In Depth
1 parent 47b0f3a commit ac681dd

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

src/_mixins.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
@mixin drag-drop {
24

35
.cdk-drag-preview {

src/app/app.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
<span>About</span>
1616
</a>
1717

18+
<a mat-list-item routerLink="drag-drop-example">
19+
<mat-icon>drag_indicator</mat-icon>
20+
<span>Drag and Drop</span>
21+
</a>
22+
1823
<a mat-list-item>
1924
<mat-icon>person_add</mat-icon>
2025
<span>Register</span>

src/app/drag-drop/drag-drop.component.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55

66
<h3>Lessons To Watch:</h3>
77

8+
<div cdkDropList class="lessons-list"
9+
(cdkDropListDropped)="drop($event)">
10+
11+
<div class="lesson" *ngFor="let lesson of lessons" cdkDrag>
12+
13+
<div class="drop-placeholder" *cdkDragPlaceholder></div>
14+
15+
{{lesson.description}}
16+
17+
</div>
18+
19+
20+
</div>
21+
822
</div>
923

1024
<!-- div class="done">

src/app/drag-drop/drag-drop.component.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
@import "../../mixins";
3+
4+
5+
@include drag-drop();
6+
7+
28
.drag-drop-container {
39
font-family: "Roboto";
410
display: flex;

src/app/drag-drop/drag-drop.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,13 @@ export class DragDropComponent {
9090
}
9191
];
9292

93+
drop(event: CdkDragDrop<Lesson[]>) {
94+
95+
console.log("previousIndex = ", event.previousIndex);
96+
97+
console.log("currentIndex = " + event.currentIndex);
98+
99+
moveItemInArray(this.lessons, event.previousIndex, event.currentIndex);
100+
101+
}
93102
}

0 commit comments

Comments
 (0)