如何自动更新值,ionic2如何在不刷新页面的情况下更新值

how update value auto, ionic2 update value without page refresh

我的 ionic2 应用程序从 cordova 插件获取数据,但输入的值没有更新 automatic.thank 你先。 我的演示代码:

import { Component } from '@angular/core';
import { NavController, Events } from 'ionic-angular';

declare var AMapPlugin;

@Component({
  selector: 'page-hello-ionic',
  templateUrl: 'hello-ionic.html'
})

export class HelloIonicPage {

  gps: string = '';
  _distance: number = 0;

  constructor(public navCtrl: NavController, private event: Events) {
  }

  getDistance() {
    return new Promise<number>((resolve, reject) => {
      AMapPlugin.getDistance(data => {
        resolve(data);
      });
    });
  }

  location() {
    AMapPlugin.startLocation(10, success => {
      let lo = { lat: success.latitude, lng: success.longitude };
      this.gps = JSON.stringify(lo);
    }, error => {
    });
  }

  start() {
    this.getDistance().then(data => {
      this._distance = data;
    });
  }
}

location 会触发 gps 每次 10 秒,但 html 值不会实时修改。

  <ion-item>
    <ion-label>distance</ion-label>
    <ion-input type="text" [(ngModel)]="_distance" readonly></ion-input>
  </ion-item>
  <ion-item>
    <ion-label>current</ion-label>
    <ion-input type="text" [(ngModel)]="gps | async" readonly></ion-input>
  </ion-item>

您必须手动检测更改。在 angular 中使用 ngZone 或其他变化检测器,检查此