源代码:
ngOnInit(): void { const button = document.querySelector('button'); fromEvent(button, 'click').pipe(map(event => (event as MouseEvent).x ), scan((count, clientX) => count + clientX, 0)) .subscribe(count => console.log(`total sum of mouse event.x: ${count} `)); }
代码中使用到的MouseEvent的定义很有意思,在这里: