我希望每10分钟显示一次会话超时弹出窗口。我将发布的时间放在会话存储中的服务文件中,并且也从同一文件中启动计时器。我这样做的原因是,在每个响应中,我都有一个新的发布时间。因此,我正在将发布时间从会话存储传递到弹出窗口。我在这里遇到的问题是我无法从该特定服务调用组件,原因是“服务中的循环依赖->组件->服务->组件”
这是我的服务文件
@Injectable({
providedIn: 'root'
})
export class HttpBaseService {
constructor(public authHttp: HttpClient, private modal: MatDialog,
private toastr: ToastrManager) { }
public handleAPIResponse(response: any) {
if (response.accessToken) {
const tokenInfo =
this.getDecodedAccessToken(response.accessToken);
const issuedTime = tokenInfo.exp;
this.setToken(response.accessToken, issuedTime);
//Here I am starting the timer with latest issued time.
this.startTimer(issuedTime);
}
return response.result;
}
}
startTimer(issuedTime: number) {
///login to calculate time
//call a modal popup here if time is up.
this.modal.open(ModalPopupComponent, {
}
}
这是我的ModalPopupComponent
@Component({
selector: 'app-modal-popup',
templateUrl: './modal-popup.component.html',
styleUrls: ['./modal-popup.component.scss'],
})
export class ModalPopupComponent implements OnInit {
//logic to show countdown of One min to logout automatically
}
需要知道如何在没有任何循环依赖的情况下从此服务调用模式组件。 在此先感谢
答案 0 :(得分:0)
您可以在组件中设置计时器,在服务中检查变量并按以下方式运行Modal:
app.get('/test/:articleID', (req, res) => {
let article_id = req.params.articleID;
let sql = `SELECT article.*, chapter.*, subchapter.*
FROM article
LEFT JOIN chapter ON article.id = chapter.articleID
LEFT JOIN subchapter ON chapter.id = subchapter.chapterID
WHERE article.id = ?`;
db.get(sql, [article_id], (err, article) => {
res.send(article)
});
})
您可以在ngOninit组件中激活它 祝你好运!