Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument of type 'Event' is not assignable to parameter of type 'CdkDragMove<any>'

I'm trying to get the position of a draggable element as it's moved around, but I can't find any attribute that works with CdkDragMove.

HTML Template

<div
  cdkDropList
  [cdkDropListData]="day.lunch"
  [cdkDropListConnectedTo]="dropTargetIds"
  class="example-list"
  (cdkDropListDropped)="drop($event)"
  (cdkDragMoved)="dragMoved($event)" // <--- Error (see below)
  >
    //Actual content
  </div>

TypeScript

dragMoved(event:CdkDragMove<any>){
    // get PosX & PosY
  }
  drop(event: CdkDragDrop<Recipe[]>) {
    // other stuff
  }

I get this error:

Argument of type 'Event' is not assignable to parameter of type 'CdkDragMove'. Type 'Event' is missing the following properties from type 'CdkDragMove': source, pointerPosition, event, distance, deltangtsc

I also tried with dragMoved instead of $event but then I get this

Argument of type '(event: CdkDragMove) => void' is not assignable to parameter of type 'CdkDragMove'. Type '(event: CdkDragMove) => void' is missing the following properties from type 'CdkDragMove': source, pointerPosition, event, distance, delta

I can't get my head around this, 'cause the event is working on the drop function instead. Any Ideas?

like image 495
Maxwelllondon Avatar asked Oct 19 '25 12:10

Maxwelllondon


2 Answers

I got this error when I had failed to import the DragDropModule into my module.

import { DragDropModule } from '@angular/cdk/drag-drop';
like image 93
adam0101 Avatar answered Oct 21 '25 03:10

adam0101


Solved

I found out that the (cdkDragMoved)="dragMoved($event)" binding had to be placed at the cdkDrag element, and not at the cdkDropList element.

<div
            cdkDropList
            [cdkDropListData]="day.lunch"
            [cdkDropListConnectedTo]="dropTargetIds"
            class="example-list"
            (cdkDropListDropped)="drop($event)"
            // It was here
          >
            <mat-chip-list class="mat-chip-list-stacked" >
              <mat-chip cdkDrag (cdkDragMoved)="dragMoved($event)"> //<--- Must be Here
                // content
              </mat-chip>
            </mat-chip-list>
          </div>
like image 40
Maxwelllondon Avatar answered Oct 21 '25 01:10

Maxwelllondon