首页 > 解决方案 > 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.

标签: angular7ionic4

解决方案


我不确定,但是我从您的问题和评论中收集到了什么,有一个主题将在简历上更新并且在每个选项卡上具有请求每个 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。


推荐阅读