【发布时间】:2020-04-16 10:40:29
【问题描述】:
我有一个要求,我想在重定向到其他页面之前显示确认弹出消息,在那里我从用户天气中获取输入,他想要离开未保存的更改。
发生了什么!
在浏览器确认对话框首先出现然后得到不正确的 HTTP-Request 响应。
应该是什么!
我希望首先获得 HTTP 响应,如果满足条件,则弹出确认对话消息。
这是我用于我的项目的代码示例。
service.ts 文件
async IsUnSavedRosterExistsTwo() {
console.log('async method called');
const url = this.util.getBaseURL() + apiURLs.IsUnSavedRosterExists;
const rr = await this.http.get<boolean>(url).toPromise();
console.log(rr);
return rr;
}
我已经尝试了所有可能的解决方案,例如 subscribe、promise、pipe,但这里没有任何效果。
component.ts
canDeactivate() {
this.saveDownloadButton = false;
// const IsUnSavedRosterExists = this.rosterService.IsUnSavedRosterExists();
const IsUnSavedRosterExists = this.rosterService.IsUnSavedRosterExistsTwo();
debugger;
if (IsUnSavedRosterExists) {
console.log('executing the code');
return confirm('You have unsaved Employee Data. Do you wish to proceed without saving?');
} else {
this.saveDownloadButton = false;
}
return this.saveDownloadButton;
}
简而言之,我想先等待http-request响应,然后执行if条件满足然后弹出确认对话框,否则重定向到其他页面。
如果我的问题不清楚,请告诉我。
【问题讨论】:
-
IsUnSavedRosterExistsTwo没有返回任何内容?它不应该返回rr
标签: angular async-await httprequest angular8