【问题标题】:remove mousemove etc events from Ng-Idle从 Ng-Idle 中删除 mousemove 等事件
【发布时间】:2025-12-06 01:20:08
【问题描述】:

我正在使用 Ng-Idle 库来检查用户在 Angular Web 应用中的不活动情况。

我已经实现了这么多库

idle.setIdle(5);
idle.setTimeout(0);
idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
idle.onIdleEnd.subscribe(() => { 
  this.idleState = 'No longer idle.'
  console.log(this.idleState);
  this.idle.watch();
  this.idleState = 'Started.';
});
idle.onIdleStart.subscribe(() => {
  this.idleState = 'You\'ve gone idle!'
  console.log(this.idleState);
});

问题是 DEFAULT_INTERRUPTSOURCES 接受所有这些 mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll 中断事件,但我只希望键盘和鼠标单击中断来停止 ng-idle .

我已尝试更改这些库文件中的事件 ---> ng-idle-core.umd.js、ng-idle-core.umd.js.map 和 ng-idle- core.metadata.json。还是没有成功。

如何实现所需的功能?

【问题讨论】:

    标签: angular ng-idle


    【解决方案1】:

    我通过下面的代码得到了想要的结果

    idle.setInterrupts(this.createCustomInterruptSources(null));
    
    createCustomInterruptSources(options) {
      return [
          new DocumentInterruptSource('keydown mousedown touchstart touchmove 
          scroll', options),
          new StorageInterruptSource(options)
      ];
    }
    

    【讨论】: