我有以下代码,我还没有设法更新stepCount的更改,我需要每次startPedometerUpdates(),发送更改以使其能够立即显示。在变量stepsCount中。
我要寻找的基本上是能够创建手表来检测var DOMParser = require('xmldom').DOMParser;
var doc = new DOMParser().parseFromString(
'<xml xmlns="a" xmlns:c="./lite">\n'+
'\t<child>test</child>\n'+
'\t<child></child>\n'+
'\t<child/>\n'+
'</xml>'
,'text/xml');
doc.documentElement.setAttribute('x','y');
doc.documentElement.setAttributeNS('./lite','c:x','y2');
var nsAttr = doc.documentElement.getAttributeNS('./lite','x')
console.info(nsAttr)
console.info(doc)
或this.stepsCount
的变化
任何想法怎么做? 非常感谢
this.pedometer.startPedometerUpdates().
HTML
import { Component } from '@angular/core';
import { Platform, NavController } from 'ionic-angular';
//Pedometer
import { Pedometer, IPedometerData } from '@ionic-native/pedometer';
@Component({
selector: 'page-actv-home',
templateUrl: 'actv-home.html',
})
export class ActvHomePage {
stepsCount: any = 0;
constructor(
public navCtrl: NavController,
public pedometer: Pedometer,
public plt: Platform
) {
this.pedometer.startPedometerUpdates()
.subscribe((data: IPedometerData) => {
this.stepsCount = data.numberOfSteps;
});
}
}
控制台日志 <ion-content>
<p>{{ stepsCount }}</p>
</ion-content>
答案 0 :(得分:0)
我有解决办法。感谢ChangeDetectorRef
,谢谢。 @ AJT_82
import { Component , ChangeDetectorRef} from '@angular/core';
import { Platform, NavController } from 'ionic-angular';
//Pedometer
import { Pedometer, IPedometerData } from '@ionic-native/pedometer';
@Component({
selector: 'page-actv-home',
templateUrl: 'actv-home.html',
})
export class ActvHomePage {
stepsCount: any = 0;
constructor(
public navCtrl: NavController,
public pedometer: Pedometer,
public refdect:ChangeDetectorRef,
public plt: Platform
) {
// STEPS COUNT DEMO
if (this.plt.is('cordova')) {
this.watchSteps();
}
}
watchSteps(){
this.pedometer.startPedometerUpdates()
.subscribe((data: IPedometerData) => {
this.stepsCount = data.numberOfSteps;
if(this.stepsCount == 10){
alert('Yes! Your have completed 100 steps');
}
this.refdect.detectChanges();
});
}
}