Angular6 若用户在过去15分钟内未在我们的网站上进行任何活动,则从网站注销

Angular6 若用户在过去15分钟内未在我们的网站上进行任何活动,则从网站注销,angular6,Angular6,如果用户在15分钟内未在我们的网站上进行任何移动,如何从网站注销?在您的应用程序中 npm install --save @ng-idle/core @ng-idle/keepalive angular2-moment 设置应用程序模块 打开src/app/app.module.ts并使用导入Ng2IdleModule import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@an

如果用户在15分钟内未在我们的网站上进行任何移动,如何从网站注销?

在您的应用程序中

npm install --save @ng-idle/core @ng-idle/keepalive angular2-moment
设置应用程序模块 打开src/app/app.module.ts并使用导入Ng2IdleModule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { NgIdleKeepaliveModule } from '@ng-idle/keepalive'; // this includes the core NgIdleModule but includes keepalive providers for easy wireup

import { MomentModule } from 'angular2-moment'; // optional, provides moment-style pipes for date formatting

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

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    MomentModule,
    NgIdleKeepaliveModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
扩展您的主要组件

import { Component, OnInit } from '@angular/core';
import { Router, NavigationStart } from '@angular/router';
import { Idle, DEFAULT_INTERRUPTSOURCES } from '@ng-idle/core';
import { Keepalive } from '@ng-idle/keepalive';


@Component({
  selector: 'app-theme',
  templateUrl: './theme.component.html',
  styleUrls: ['./theme.component.css']
})
export class AppComponent implements OnInit {
  lastPing?: Date = null;


  constructor(private route: Router, private idle: Idle, private keepalive: Keepalive) {
    idle.setIdle(5);
    idle.setTimeout(900);
    idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
    idle.onIdleEnd.subscribe(() => { });

    idle.onTimeout.subscribe(() => {
      this.logout();
    });
    idle.onIdleStart.subscribe(() => {
    });
    idle.onTimeoutWarning.subscribe((countdown) => {
    });

    keepalive.interval(5);

    keepalive.onPing.subscribe(() => this.lastPing = new Date());

    this.reset();


  }

  ngOnInit() {
  }

  reset() {
    this.idle.watch();

  }

  logout() {
   //--
// LogoutCode
//---
  }
}