相关疑难解决方法(0)

我如何在整个页面上收听按键事件?

我正在寻找一种方法将函数绑定到我的整个页面(当用户按下一个键时,我希望它在我的conponent.ts中触发一个函数)

在Angular 1中它很容易ng-keypress但是它没有用(keypress)="handleInput($event)".

我在整个页面上使用div包装器尝试了它,但它似乎不起作用.它只适用于焦点在它上面.

<div (keypress)="handleInput($event)" tabindex="1">
Run Code Online (Sandbox Code Playgroud)

谢谢!

keypress key-bindings typescript angular

86
推荐指数
4
解决办法
8万
查看次数

如何在角度6中赋予会话空闲超时?

我们正在根据用户角色维护会话。我们想在会话空闲5分钟时实现超时功能。我们正在使用@ ng-idle / core npm模块来做到这一点。

我的服务文件:

 import { ActivatedRouteSnapshot } from '@angular/router';
 import { RouterStateSnapshot } from '@angular/router';
 import {Idle, DEFAULT_INTERRUPTSOURCES, EventTargetInterruptSource} from 
 '@ng-idle/core';
 @Injectable()
export class LoginActService implements CanActivate {
constructor(private authService: APILogService, private router: 
 Router,private idle: Idle) {
  idle.setIdle(10);
  idle.setTimeout(10);
 }
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot
 ): Observable<boolean>|Promise<boolean>|boolean {
let role = localStorage.getItem('currentUser');

if (localStorage.getItem('currentUser')) {
  if(next.data[0] == role){
   },600000) 
    return true;
  } 
}
else{
  this.router.navigate(['/'], { queryParams: { returnUrl: state.url }});
  return false;
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

作为示例,我使用了setIdle超时5秒钟,但这没有发生。有人可以指导我该怎么做吗?

session angular angular6

6
推荐指数
3
解决办法
2万
查看次数

标签 统计

angular ×2

angular6 ×1

key-bindings ×1

keypress ×1

session ×1

typescript ×1