1
ログアウトボタンをクリックすると、ng2-idleが動作し続けるのが問題です。 この問題を解決するために、setIdle関数とsetTimeout関数を1秒間再設定します。角度2 - ng2-idleを使用したログアウト
しかし、ユーザーがログイン画面に転送されると、アプリはタイムアウトを得るのに1秒かかります。
logout()関数を呼び出すログアウトボタンをクリックした後に、タイムアウトを強制する方法やng2-idleを終了する方法があるかどうかを知りたい。
logout() {
this.idle.stop();
this._headerService.exit()
.subscribe(
data => {
localStorage.clear();
this._router.navigate(['/auth']);
},
error => console.log(error)
)
}
this.idle.stop()
またはthis.idle.ngOnDestroy();
idle.ts
this.idle.ngOnDestroy();
がthis.idle.stop()
とthis.clearInterrupts();
含まれて両方の機能を使用することが可能である:
import {Component} from '@angular/core';
import {Router} from "@angular/router";
import {Http, Headers} from "@angular/http";
import {NgClass} from '@angular/common';
import {Observable} from "rxjs/Observable";
import 'rxjs/Rx';
import {HeaderService} from './header.service';
import {Idle, DEFAULT_INTERRUPTSOURCES} from 'ng2-idle/core';
@Component({
selector: 'my-header',
templateUrl: './js/app/header/header.component.html',
styleUrls: ['./js/app/header/header.component.css']
})
export class HeaderComponent {
nome = localStorage['nome'];
constructor(private _router: Router, private _http: Http, private _headerService: HeaderService, private idle: Idle) {
idle.setIdle(5);
idle.setTimeout(1800);
idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
idle.onTimeoutWarning.subscribe((countdown:number) => {
console.log('TimeoutWarning: ' + countdown);
});
idle.onTimeout.subscribe(() => {
console.log('Timeout');
localStorage.clear();
this._router.navigate(['/auth', {sessionExpirate: 'true'}]);
});
idle.watch();
}
logout() {
this.idle.setIdle(1);
this.idle.setTimeout(1);
this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
this._headerService.exit()
.subscribe(
data => {
this.idle.onTimeout.subscribe(() => {
console.log('Timeout');
localStorage.clear();
this._router.navigate(['/auth']);
},
error => console.log(error)
)}
)
}
}
はまだアクティブなng2-idleプロジェクトですか?あなたは私にリンクを送ってもらえますか? –
私はそう信じています。サイトはhttps://www.npmjs.com/package/@ng-idle/coreにもあります。https://github.com/HackedByChinese/ng2-idle – rafaelcb21