0
我的ionic2应用程序从cordova插件获取数据,但输入的值没有更新automatic.thank你先。 我的演示代码:如何更新值auto,ionic2更新值无页面刷新
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;
});
}
}
位置将触发全球定位系统每次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>
gps是一个字符串..不是一个承诺或可观察..不需要'异步'。也是'location()'调用? –
'getDistance()'是一个Promise(只读一次)。为了读取新的值,你最好提供一个Observable。 –