我试图根据光标的位置更改元素的位置。因此,我有以下代码:
this.ngZone.runOutsideAngular(() => {
fromEvent(window, 'mousemove').pipe(
filter(() => this.hoveredCart !== -1),
).subscribe(({clientY}) => this.floatingElements.toArray()[this.hoveredCart].nativeElement
.style.top = clientY);
});
以某种方式返回错误:
类型“事件”上不存在属性“ clientY”
答案 0 :(得分:1)
fromEvent
使用通用类型,因此您可以告诉TypeScript
它应为哪种类型:
fromEvent<MouseEvent>(window, 'mousemove').pipe(
filter(() => this.hoveredCart !== -1),
).subscribe(({clientY}) => this.floatingElements.toArray()[this.hoveredCart].nativeElement
.style.top = clientY);