简体   繁体   English

AngularJS:如何在一定时间间隔后调用函数?

[英]AngularJS: how can I call a function after certain time interval?

My Scenario is: 我的情景是:

I want to call logout function after let say 30 mins automatically in my app. 我想在我的应用程序中自动说30分钟后调用注销功能。 Is this possible to acheive this? 这有可能实现吗? And more over i want to know the time of user's last interactivity with my application. 而且我想知道用户上次与我的应用程序交互的时间。 Can anybody help me regarding this?? 关于这个可以帮助我吗?

Use below for any function that requires time out. 以下用于需要超时的任何功能。 But I will not suggest this for Logout. 但我不建议退出。 Better you can use browser session to logout after 30 min. 最好在30分钟后使用浏览器会话注销。

$timeout(function() {
   // your code
}, 3000); // 3 seconds

use setTimeout() pure javascript function that can be invoked after a time of interval 使用setTimeout()纯javascript函数,可以在一段时间后调用

 setTimeout(function(){
    logout();
},5000)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM