getUserByToken 在 auth.service 调用 double

问题描述

我今天尝试使用 metronic,发现 auth.service 中的 getUserByToken 方法总是调用 double,这是正常的还是某些错误?因为当我们开始使用 ajax post 来填充用户详细信息时,这将调用相同的 ajax 2x。

我使用的是带有角度的 metronic 7。

解决方法

我找到了为什么这总是双 ajax 的根本原因

auth service constructor called
auth.service.ts:72 getUserByToken called
app.module.ts:23 APP_INITIALIZER appInitializer(authService: AuthService) called
auth.service.ts:72 getUserByToken called

在 app 模块中定义 APP_INITIALIZER 来检查令牌,并且在类的构造函数中已经创建了订阅。但是我不知道当我在构造函数效果中删除订阅时。