【问题标题】:Angular 6 : is there any chance of performance issue when using @HostListener?Angular 6:使用@HostListener 时是否存在性能问题?
【发布时间】:2018-10-16 05:50:54
【问题描述】:

我有一个 Angular 应用程序,如果用户让浏览器长时间闲置,我想自动从应用程序中退出。说15分钟。为此,我编写了一项服务,并且工作正常。我正在使用 @HostListener 捕捉用户操作。但我觉得,可能会出现性能问题,因为每个用户操作都会调用 HostListener 方法。

@HostListener('document:keyup', ['$event'])
  keyUpListenere(event) {
   this.idleTimeoutService.resetTimer();
   }
   @HostListener('document:click', ['$event'])
   clickListener() {
    this.idleTimeoutService.resetTimer();     
    }
   @HostListener('document:wheel', ['$event'])
   mouseWheelListener () {
    this.idleTimeoutService.resetTimer();
    }

【问题讨论】:

    标签: rxjs angular6


    【解决方案1】:

    完全没有,许多应用程序使用这种东西来自动弹出会话超时提醒。我还会包括 touchstart 和/或 touchend。

    【讨论】:

    • 阿德里安,你愿意简单解释一下,还是链接到一些解释为什么 HostListeners 保存以使用,关于内存?
    【解决方案2】:

    是的,有表现的机会,认为您正在创建 3 个侦听器来侦听所有文档上的操作。

    你可以在事件函数的app.component的主div上分配这个事件,比做监听器要好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 2018-05-26
      • 2019-06-08
      • 2011-07-19
      • 1970-01-01
      相关资源
      最近更新 更多