Angular 2键侦听器事件未触发

时间:2016-12-05 10:19:23

标签: angular ionic2

我使用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;
      }
    }

0 个答案:

没有答案