Angular Material 7 拖放的 x 和 y 坐标
创始人
2024-10-19 15:00:27
0

要在Angular Material 7中获取拖放元素的x和y坐标,您可以使用Angular CDK的DragDrop模块。以下是一个示例解决方案,其中包含代码示例:

  1. 在您的Angular项目中安装Angular CDK和Angular Material:
npm install @angular/cdk
npm install @angular/material
  1. 在您的模块中导入DragDropModule:
import { DragDropModule } from '@angular/cdk/drag-drop';

@NgModule({
  imports: [
    DragDropModule
  ]
})
export class YourModule { }
  1. 在您的组件中使用DragDrop模块,实现拖放功能,并获取拖动元素的x和y坐标:
import { Component } from '@angular/core';
import { CdkDragEnd } from '@angular/cdk/drag-drop';

@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
export class YourComponent {
  xCoord: number;
  yCoord: number;

  onDragEnded(event: CdkDragEnd) {
    this.xCoord = event.source.getFreeDragPosition().x;
    this.yCoord = event.source.getFreeDragPosition().y;
  }
}
  1. 在您的模板中将onDragEnded方法绑定到拖放元素的cdkDragEnded事件:
Draggable Element

X Coordinate: {{ xCoord }}

Y Coordinate: {{ yCoord }}

当您拖动可拖动元素时,onDragEnded方法会被触发,并且xCoord和yCoord变量会被更新为拖动元素的当前x和y坐标。您可以在模板中显示这些坐标以进行测试和验证。

相关内容

热门资讯

2分钟要领!wpk透视辅助方法... 2分钟要领!wpk透视辅助方法(透视)一直有辅助教程(哔哩哔哩)1、金币登录送、破产送、升级送、活动...
第一分钟模块!wepoker透... 第一分钟模块!wepoker透视底牌脚本(透视)切实真的是有辅助辅助(哔哩哔哩)一、wepoker透...
第9分钟绝活儿!红龙poker... 第9分钟绝活儿!红龙poker作必弊指令(透视)竟然存在有辅助工具(哔哩哔哩)一、红龙poker作必...
第3分钟办法!哈糖大菠萝破解器... 第3分钟办法!哈糖大菠萝破解器(透视)总是是有辅助教程(哔哩哔哩)1、进入到哈糖大菠萝破解器是否有挂...
四分钟步骤!wejoker辅助... 四分钟步骤!wejoker辅助软件视频(透视)确实存在有辅助神器(哔哩哔哩)进入游戏-大厅左侧-新手...
6分钟攻略!wejoker辅助... 6分钟攻略!wejoker辅助软件(透视)都是是真的有辅助透视(哔哩哔哩)wejoker辅助软件辅助...
第五分钟指南书!hhpoker... 第五分钟指南书!hhpoker免费透视脚本(透视)其实是真的有辅助教程(哔哩哔哩)1)hhpoker...
第九分钟绝活!wepoker有... 第九分钟绝活!wepoker有没有机器人(透视)一贯是有辅助教程(哔哩哔哩)1、wepoker有没有...
第9分钟讲义!wepoker透... 第9分钟讲义!wepoker透视底牌脚本(透视)总是真的是有辅助透视(哔哩哔哩)1、许多玩家不知道w...
四分钟大纲!epoker免费透... 四分钟大纲!epoker免费透视脚本(透视)竟然是真的有辅助下载(哔哩哔哩)1、任何epoker免费...