我想提醒用户他是否闲置了 20 分钟。所以,创建了一个服务。
它在桌面上运行良好,但在手机中没有显示,有时如果屏幕在后台停留几个小时,然后注销对话框屏幕会在我再次进入页面后开始倒计时。
我的意思是它应该注销,我应该看到登录页面,但在这里它会在几个小时后显示注销警报倒计时页面,否则它不会显示在移动浏览器中。
这是我的代码,请让我知道我缺少哪个逻辑。
这是 Service.ts 文件。check() 将每 5 秒调用一次,注销警报将在 20 秒后显示...
const MINUTES_UNITL_AUTO_LOGOUT = 0.2; // 1 mins- 20
const CHECK_INTERVAL = 5000; // checks every 5 secs- 5000
@Injectable({
providedIn: "root",
})
export class AutoLogoutService {
logOutInterval: any;
constructor(
private localStorage: LocalStoreManager,
private authService: AuthService,
public dialog: MatDialog
) {
this.localStorage.savePermanentData(
Date.now().toString().toString(),
DBkeys.AUTO_LOGOUT
);
this.initListener();
}
initListener() {
document.body.addEventListener("click", () => this.reset());
document.body.addEventListener("mouseover", () => this.reset());
document.body.addEventListener("mouseout", () => this.reset());
document.body.addEventListener("keydown", () => this.reset());
document.body.addEventListener("keyup", () …Run Code Online (Sandbox Code Playgroud) 我已经在我的后端初始化了 WebSocket。
然后使用rxjs/webSocket连接,在浏览器上收到如下错误:
connection to 'ws://localhost:3000/' failed: Connection closed before receiving a handshake response
Run Code Online (Sandbox Code Playgroud)
server.js 相关代码:
connection to 'ws://localhost:3000/' failed: Connection closed before receiving a handshake response
Run Code Online (Sandbox Code Playgroud)
app.js 相关代码:
const { app, onServerInitialized } = require('./app');
const port = normalizePort(process.env.PORT);
console.log('Server is running on port ' + process.env.PORT);
app.set('port', port);
const server = http.createServer(app);
onServerInitialized(server);
Run Code Online (Sandbox Code Playgroud)
网络套接字服务
const app = express();
const onServerInitialized = server => {
const io = socketio(server);
io.on('connection', socket => {
console.log('subscrie');
});
};
module.exports = { …Run Code Online (Sandbox Code Playgroud) 我正在使用路由器解析器以便在加载页面之前获取我的 ngrx 存储数据。将解析器插入我的路由后,路由器不会生成我的内容
<router-outlet></router-outlet>
Run Code Online (Sandbox Code Playgroud)
其他路由(没有解析器)运行良好,如果我从路由中删除解析器,则页面加载得很好。
我的解析器文件:
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { MenuItem } from '../navbar/menuItem.model';
import * as fromApp from '../store/app.reducer';
@Injectable()
export class MenuItemsResolver implements Resolve<MenuItem[]> {
constructor(
private store: Store<fromApp.AppState>
) {}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
Observable<MenuItem[]> | Promise<MenuItem[]> | MenuItem[]
{
return this.store.select('menuItems').pipe(
map((data: { menuItems: MenuItem[] }) …Run Code Online (Sandbox Code Playgroud) 我正在使用 ng-recaptcha 包来在我的网络应用程序中实现 Google reCAPTCHA V3。为此,我创建了一个服务,它将在客户端执行所有需要的操作。
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ReCaptchaV3Service, OnExecuteData } from 'ng-recaptcha';
import { environment } from 'src/environments/environment';
const BACKEND_URL = environment.apiUrl + '/contact/';
@Injectable()
export class ContactService {
constructor(
private http: HttpClient,
private recaptchaV3Service: ReCaptchaV3Service
) {}
public sendContactForm(data): void {
this.recaptchaV3Service.execute('contactForm').subscribe(data => {
console.log(data);
});
// this.http.post(BACKEND_URL, data)
// .subscribe((responseData) => {
// console.log(responseData);
// });
}
}Run Code Online (Sandbox Code Playgroud)
不幸的是,在执行 recaptcha 时(在 sendContactForm 方法上),我收到以下错误:
“未捕获(承诺):[对象空]”
这里有什么问题?
我已经在我的应用程序上安装了 angular Universal。运行npm run build:ssr- 完成。作品。运行npm run server:ssr- DONE.WORKS。
访问服务器 URL (localhost:4000) 后,页面未完全加载并在终端上引发以下错误:
node.js express server-side-rendering angular-universal angular
angular ×5
javascript ×2
node.js ×2
express ×1
logout ×1
mat-dialog ×1
ngrx ×1
recaptcha ×1
rxjs ×1
typescript ×1
websocket ×1