我希望能够记录用户点击按钮所需的时间。我已经解决了这个问题,但如果有更好的解决方案,我想尝试一下。以下是我的解决方法:
export class MainComponent implements OnInit {
timer : number = 0;
intervalId : number;
constructor() {
this.intervalId = setInterval(() => {
this.timer++;
}, 1000);
}
ngOnInit() {}
buttonClick = function() {
alert(this.timer);
this.timer = 0;
}
}