1
我正在使用ionic 2並擁有類似以下的類。我正在使用locationServices插件,不想使用離子本地地理位置插件。數據成員的值在Typescript中沒有改變
export class a{
location_acquiring:boolean;
location_available:boolean;
constructor(){
this.location_acquiring=true;
this.location_available=false;
}
fun(){
//Here i am using some cordova plugins and setting the location latitude and longitude localstorage variables.
let self=this;
cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
let selfa=self;
cordova.plugins.diagnostic.isLocationAvailable(function(available){
let selfb=selfa;
cordova.plugins.locationServices.geolocation.watchPosition(function(position) {
//Now here although project is build without errors. but the values of the variables are not updated.
selfb.location_acquiring=false;
selfb.location_available=true;
},function(error){});
},function(error){});
},function(error){});
}
show_values(){
console.log(this.location_acquiring);
console.log(this.location_available);
}
}
locationServices插件內部的變量更改不會反映在類變量中。
的show_values()
功能
真正的輸出
假
未經測試且可能不相關,但對於Google地圖API,您需要明確地在zone.js中運行一些回調。如果你嘗試在構造函數中注入'private __zone:NgZone'(NgZone生活在angular/core中),然後執行:this._zone.run(()=> {self_location_acquiring = false; selfb。 location_available = true; });' –