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

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

本文关键字:时间 函数 调用 AngularJS      更新时间:2023-09-26

我的场景是:

我想在我的应用程序中自动显示30分钟后调用注销功能。这有可能实现吗?此外,我想知道用户最后一次与我的应用程序交互的时间。有人能帮我吗??

对于任何需要超时的函数,请使用以下内容。但我不会建议Logout这样做。最好您可以使用浏览器会话在30分钟后注销。

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

使用setTimeout()纯javascript函数,该函数可以在间隔一段时间后调用

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