Angular应用程序的默认空闲超时时间是多少?
创始人
2024-10-30 13:00:58
0

Angular应用程序的默认空闲超时时间是5分钟。可以通过在应用程序的根模块中配置Idle服务来修改默认超时时间。

首先,安装@ng-idle/core@ng-idle/keepalive依赖项:

npm install @ng-idle/core @ng-idle/keepalive

然后,在根模块中导入NgIdleModuleKeepaliveModule

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgIdleKeepaliveModule } from '@ng-idle/keepalive';
import { IdleModule } from '@ng-idle/core';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    NgIdleKeepaliveModule.forRoot(),
    IdleModule.forRoot()
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

接下来,在应用程序的根组件中使用Idle服务来配置空闲超时时间:

import { Component } from '@angular/core';
import { Idle } from '@ng-idle/core';

@Component({
  selector: 'app-root',
  template: ``
})
export class AppComponent {
  constructor(private idle: Idle) {
    // 设置空闲超时时间为5分钟
    idle.setIdle(300);
    // 设置警告时间为30秒
    idle.setTimeout(30);
    // 设置警告消息
    idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
    // 启动Idle服务
    idle.watch();
  }
}

以上代码将将空闲超时时间设置为5分钟,警告时间设置为30秒,并启动Idle服务。

注意:在应用程序中使用Idle服务之前,需要确保用户已经登录,否则可以通过路由守卫或其他方式来限制访问。

相关内容

热门资讯

实测交流!hhpoker是真的... 实测交流!hhpoker是真的还是假的,菠萝辅助器免费版的特点,安装教程(有挂方法)科技教程也叫必备...
玩家必看科普!德普之星app安... 此外,数据分析德州(德普之星app安卓版破解版)辅助神器app还具备辅助透视行为开挂功能,通过对客户...
记者揭秘!aapoker发牌逻... 记者揭秘!aapoker发牌逻辑,哈糖大菠萝软件下载,可靠技巧(有挂透视);1分钟了解详细教程(微信...
大家学习交流!wepoker线... 大家学习交流!wepoker线上大神,wpk私人辅助,科技教程(有挂方法)1、点击下载安装,微扑克w...
必备攻略!wepoker智能辅... 必备攻略!wepoker智能辅助插件,wepoker辅助透视,2025新版教程(有挂攻略);原来确实...
玩家必备教程!wepoker国... 玩家必备教程!wepoker国外版透视,wepoker怎么挂底牌,解密教程(有挂辅助);人气非常高,...
重大发现!wepoker新号好... 1、重大发现!wepoker新号好一点吗,wepokerplus辅助,详细教程(有挂辅助)(UU p...
专业讨论!wepoker怎么获... 此外,数据分析德州(wepoker辅助器软件下载)辅助神器app还具备辅助透视行为开挂功能,通过对客...
必备攻略!wepoker国外版... 必备攻略!wepoker国外版透视,wepoker透视底牌,介绍教程(有挂攻略)科技教程也叫必备教程...
一分钟了解!wpk刷入池率脚本... 一分钟了解!wpk刷入池率脚本,大菠萝辅助器,必赢方法(有挂透明);wpk刷入池率脚本软件透明挂更新...