要在Angular 7中在图像上添加评论并获取所选点的x、y坐标,可以按照以下步骤操作:
ng new image-comments
cd image-comments
ng generate component image-comments
Image Comments
Selected Coordinates: {{ selectedX }}, {{ selectedY }}
import { Component } from '@angular/core';
@Component({
selector: 'app-image-comments',
templateUrl: './image-comments.component.html',
styleUrls: ['./image-comments.component.css']
})
export class ImageCommentsComponent {
selectedX: number;
selectedY: number;
getImageCoordinates(event: MouseEvent) {
this.selectedX = event.clientX;
this.selectedY = event.clientY;
}
}
ng serve --open
现在,当你在图像上点击时,将会获取到所选点的x、y坐标,并显示在页面上。你可以将上面的代码示例替换为你的实际图像和样式。