【问题标题】:How to make asynchronous REST API calls in ionic 2?如何在 ionic 2 中进行异步 REST API 调用?
【发布时间】:2017-02-22 06:18:09
【问题描述】:

我正在为一所学校构建一个应用程序。学生可以扫描身份证并进入。在教师方面的应用程序中,我显示了特定班级的学生人数。现在,我正在使用刷新器加载页面以显示学生人数。

<ion-content>
  <ion-refresher (ionRefresh)="doRefresh($event)">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>
</ion-content>



export class NumberOfStudents{
  doRefresh(refresher) {
    console.log('Begin async operation', refresher);
    setTimeout(() => {
      console.log('Async operation has ended');
      refresher.complete();
    }, 2000);
  }
}

帮助我实现在后台自动执行上述代码而无需刷新。告诉我如何在不影响视图的情况下每 2 分钟调用一次 api。

【问题讨论】:

标签: angular ionic-framework ionic2


【解决方案1】:

如果您不关心“刷新”API 调用是否比您的时间间隔(2 分钟)长,那么您可以使用 setInterval():

setInterval(doRefresh, 1000*60*2);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-04
    • 2015-01-27
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    相关资源
    最近更新 更多