angular7 - Ionic 4 - Platform.resume event calling
问题描述
I have an Ionic 4 app in which we have three tabs. Each tab contains data which will be retrieved from api call. The data will change frequently.
When we move between tabs the api will be called and the data will be re-binded. We had a requirement that when the app is minimized and open again the api has to be called and the data has to be re-binded.
I used the platform resume event as below in all the three tabs.
this.platform.ready().then(() => {
this.platform.resume.subscribe((e) => {
// API call of each function (different api for tabs)
});
});
Now, When the app is resumed after minimized, the platform resume event is called by it is calling multiple times as I used resume event in all the three tabs.
Please help to overcome this problem. Thanks in advance.
解决方案
我不确定,但是我从您的问题和评论中收集到了什么,有一个主题将在简历上更新并且在每个选项卡上具有请求每个 API 侦听该 observable 的功能是有意义的吗?
像这样:(在主应用程序上)
this.platform.ready().then(() => {
this.platform.resume.subscribe((e) => {
this.appResumedSubject.next(true);
});
});
在 tab1 上:
this.appResumedObservable.subscribe(result => {
if(result){
this.apiCall1();
}
});
在 tab2 上:
this.appResumedObservable.subscribe(result => {
if(result){
this.apiCall2();
}
});
为了使其在两个选项卡上无缝工作,需要在服务提供者上定义 appResumeSubject。
推荐阅读
- mysql - MySQL 多个 JOINS 在同一个单元格上
- css - 为什么使用 Bootstrap 4 在顶行和导航栏之间有一个空格?
- javascript - 如何将 React Hooks 与 video.js 一起使用?
- objective-c - Clang 将 #import 语句误解为文件,而不是框架
- python - 如何在文本字段中创建有效的 HTML 标签
- javafx - JavaFX中时间轴的场景更改问题
- javascript - 为什么我的 JavaScript 代码算术方程出现 NaN 错误
- javascript - 父子组件之间的 2 路事件绑定不起作用
- c++ - 在头文件和 cpp 文件中都包含一个库
- asp.net-web-api - Owin WebAPI 最大并发连接数