【发布时间】:2019-10-16 05:14:47
【问题描述】:
我不确定这是否可行,所以会尽量解释清楚。我只在 Ionic 1 中体验过之后就跳到 Ionic 4,并且有很多成长的烦恼。在我的 Ionic 1 应用程序中,我有很多功能,其中包括 ionic 弹出窗口,并且弹出窗口将是完成功能不可或缺的一部分。
也就是说,我正在使用类似于此答案的代码:https://stackoverflow.com/a/55041136/5306408
我的整体代码的基本工作方式是:
- 我在页面中有一个可点击的项目。
- 单击该页面会启动服务功能。
- 服务函数调用一个 URL,并且在理想情况下将从该 URL 检索到的数据返回到页面。
- 但是,在某些情况下,用户需要提供附加信息。理想情况下,我希望这发生在模态中:一旦用户填写了正确的信息,模态就会关闭,然后该函数将继续执行其初始目标,即调用 URL 并返回从中检索到的数据,并按预期将其返回到第 1 步中的页面。
基本上:
页面:
...
pageFunction() void {
this.someService.someFunction('someURL').then(dataFromTheURL) => {
//do something with dataFromTheURL
})
}
...
一些服务:
...
async openModal(params) {
const modal = await this.modalController.create({
component: someLoginModalPage,
componentProps: { ... }
});
modal.onDidDismiss().then((dataReturned) => {
//need a way to pass dataReturned back to pageFunction()
});
return await modal.present();
}
someFunction(url): Promise<any> {
return new Promise<any>((resolve) {
if (condition is fine and no modal is needed) {
this.http.get(url, {headers: someHeaderObject}).subscribe(result => {
resolve(result)
})
}
else {
//here is the crux of the problem - I need indicatorThatModalHasBeenClosed to come from the modal being closed, not opened
this.openModal(someParams).then((indicatorThatModalHasBeenClosed) => {
//do something with indicatorThatModalHasBeenClosed
this.http.get(url, {headers: someHeaderObject}).subscribe(result => {
resolve(result)
})
});
}
})
}
这可能与 Angular 模式有关吗?我很难找到它的任何示例,因为openModal 的代码返回modal.present() 结果,而不是通过modal.onDidDismiss() 传递的数据。最终,我想要一个打开模态的函数(返回一个 Promise),以通过关闭同一个模态提供的数据来解析。
【问题讨论】:
标签: angular ionic-framework ionic4