我使用angular 2完成了会话超时功能。但我需要在用户处于活动状态时重置标志。但是关键的听众没有正常工作。
当按键或按键时,'handleTimeOut()'功能无法调用。
@Component({
templateUrl: 'build/app.html',
directives: [LoadingModal],
host: {
'(document:keypress, document:keydown)': 'handleTimeOut($event)'
}
})
class ConferenceApp {
idleTime: any;
constructor(
public events: Events
){
platform.ready().then(() => {
this.idleTime = 0;
setInterval(() => {
this.idleTime = this.idleTime+1;
//3 mintues
if(this.idleTime > 4){
this.events.publish('appclose:presented', 'Session Timed Out', "Your session has timed out, Please close the app.");
}
}, 60*1000);
});
}
handleTimeOut(event){
console.log('inside handle timed out');
this.idleTime = 0;
}
}