Ionic 2函数调用不在函数内部工作

时间:2017-09-14 08:35:49

标签: angular cordova ionic-framework ionic2 cordova-plugins

如果启用GPS或者如果没有显示GPS开启请求对话框,我试图显示吐司消息,如果接受,则在加载视图后在ionic2 android应用程序中显示toast消息。问题是当我没有启用GPS应用程序要求通过对话框打开它。但是当我打开GPS时,它不会显示Toast消息“Loaded 2”,但它在控制台日志中显示“Loaded 2”。如何在请求后调用此presentToastMsg函数。

ionViewDidEnter() {
let options = {
  enableHighAccuracy: true,
  timeout: 1500
};

this.geolocation.getCurrentPosition(options).then((position) => {
  console.log('Loaded 1');
  this.presentToastMsg('Loaded 1');
}).catch(function (error) {
  cordova.plugins.locationAccuracy.canRequest(function (canRequest) {
    if (canRequest) {
      cordova.plugins.locationAccuracy.request(function (success) {
        console.log('Loaded 2');
        this.presentToastMsg('Loaded 2');
      }, function (error) {
        console.log(error);
        this.presentToastMsg(error);
      },
        cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
    }
  });
});
}

presentToastMsg(msg) {
let toast = this.toastCtrl.create({
  message: msg,
  duration: 3000,
  position: 'bottom',
  cssClass: "toast-info"
});

toast.present();
}

0 个答案:

没有答案