Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在Ionic应用程序中单击“确定”时重定向到其他页面_Angular_Ionic Framework - Fatal编程技术网

Angular 在Ionic应用程序中单击“确定”时重定向到其他页面

Angular 在Ionic应用程序中单击“确定”时重定向到其他页面,angular,ionic-framework,Angular,Ionic Framework,我是爱奥尼亚的新手,正在开发爱奥尼亚的应用程序。当用户设备位置关闭时,我没有在页面中显示警告消息。此警报消息工作正常。现在我的要求是,当警报消息单击OK时,将应用重定向到不同的页面(home.page.html)。我曾经返回这个主页,但它不工作。我想我需要编写一些函数来将其重定向到主页。下面是我的代码 location.ts页面: ngOnInit() { this.helperService.showLoader("Fetching your location"); thi

我是爱奥尼亚的新手,正在开发爱奥尼亚的应用程序。当用户设备位置关闭时,我没有在页面中显示警告消息。此警报消息工作正常。现在我的要求是,当警报消息单击OK时,将应用重定向到不同的页面(home.page.html)。我曾经返回这个主页,但它不工作。我想我需要编写一些函数来将其重定向到主页。下面是我的代码

location.ts页面:

ngOnInit() {
this.helperService.showLoader("Fetching your location");
this.mapElement = this.mapElement.nativeElement;
this.getUserLocation()
  .then((res) => {
    this.myLocation = res;
    this.helperService.hideLoader();
    return this.myLocation;
  })
  .catch((error) => {
      console.log('Error getting location', error);
      this.helperService.hideLoader();

      alert(
        "Location setting should be ON to use this feature, please turn it ON in the Location Settings on your phone "
      );

      return this.homePage;
  })

请帮我怎么做。谢谢

您可以使用NavController将应用程序导航到主页

爱奥尼亚V3:

Ionic V4+:this.navCtrl.navigateRoot('/home')

使用烤面包机控制器而不是警报()

})


您可以根据需要添加按钮

您可以使用NavController将应用程序导航到主页

爱奥尼亚V3:

Ionic V4+:this.navCtrl.navigateRoot('/home')

使用烤面包机控制器而不是警报()

})


您可以根据需要添加按钮

而不是JavaScript警报。您应该使用Ionic警报。这将为您提供回调

我在下面添加了示例代码,请使用此代码。我在示例代码中添加了两个
ok和cancel
按钮,如果您想在其中添加一个按钮,可以将其从数组中删除

//导入语句

import { AlertController } from '@ionic/angular';
//构造函数

constructor(private alertController : AlertController) {
    
}
在页面类中添加这两个函数

ngOnInit() {
    this.helperService.showLoader("Fetching your location");
    this.mapElement = this.mapElement.nativeElement;
    this.getUserLocation()
      .then((res) => {
        this.myLocation = res;
        this.helperService.hideLoader();
        return this.myLocation;
      })
      .catch((error) => {
        console.log('Error getting location', error);
        this.helperService.hideLoader();

        this.presentAlertConfirm(
          "Location setting should be ON to use this feature, please turn it ON in the Location Settings on your phone "
        );

      })
  }

  async presentAlertConfirm() {
    const alert = await this.alertController.create({
      cssClass: 'my-custom-class',
      header: 'application name',
      message: 'Location setting should be ON to use this feature, please turn it ON in the Location Settings on your phone',
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          cssClass: 'secondary',
          handler: (blah) => {
            console.log('Confirm Cancel: blah');
          }
        }, {
          text: 'Okay',
          handler: () => {
            console.log('Confirm Okay');
             //you can write your code or redirection 
             // sample redirection code 
             // this.router.navigate(['homepage'])
          }
        }
      ]
    });

    await alert.present();
  }

您应该使用离子警报而不是JavaScript警报。这将为您提供回调

我在下面添加了示例代码,请使用此代码。我在示例代码中添加了两个
ok和cancel
按钮,如果您想在其中添加一个按钮,可以将其从数组中删除

//导入语句

import { AlertController } from '@ionic/angular';
//构造函数

constructor(private alertController : AlertController) {
    
}
在页面类中添加这两个函数

ngOnInit() {
    this.helperService.showLoader("Fetching your location");
    this.mapElement = this.mapElement.nativeElement;
    this.getUserLocation()
      .then((res) => {
        this.myLocation = res;
        this.helperService.hideLoader();
        return this.myLocation;
      })
      .catch((error) => {
        console.log('Error getting location', error);
        this.helperService.hideLoader();

        this.presentAlertConfirm(
          "Location setting should be ON to use this feature, please turn it ON in the Location Settings on your phone "
        );

      })
  }

  async presentAlertConfirm() {
    const alert = await this.alertController.create({
      cssClass: 'my-custom-class',
      header: 'application name',
      message: 'Location setting should be ON to use this feature, please turn it ON in the Location Settings on your phone',
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          cssClass: 'secondary',
          handler: (blah) => {
            console.log('Confirm Cancel: blah');
          }
        }, {
          text: 'Okay',
          handler: () => {
            console.log('Confirm Okay');
             //you can write your code or redirection 
             // sample redirection code 
             // this.router.navigate(['homepage'])
          }
        }
      ]
    });

    await alert.present();
  }

嗨@Hitesh Patel,非常感谢你的回答。我不知道当我应用你的代码时,位置关闭功能不起作用,也没有显示警报。只能使用javascript警报进行重定向。请帮帮我。谢谢控制台中有错误吗?嗨@Hitesh Patel,非常感谢您的回答。我不知道当我应用你的代码时,位置关闭功能不起作用,也没有显示警报。只能使用javascript警报进行重定向。请帮帮我。谢谢控制台中的任何错误?嗨@Taylor Rahul,谢谢你的回答。当我应用你的代码时,我发现了一些错误。我是这方面的新手,我不知道该怎么处理这些东西。是否可以重定向到仅保留此javascript警报的其他页面。请帮忙。谢谢你能告诉我你得到了什么吗。。你可以更新你的问题。我们将一起解决这个问题。。JavaScript没有提供这个回调,所以这对您来说是有问题的。我已经更新了我的答案,并添加了几乎所有的声明。请现在查看@Taylor Rahul,获取错误无法找到名称“PresentalertConfig”。还可以在页面中添加的其他警报中获取错误。如果在聊天室中继续讨论,我将准确地分享这个问题,这将是非常棒的。对不起,我忘记在函数名之前添加这个。我再次更新了我的代码。请使用最新版本。如果您还有任何错误,请告诉我Hi@Taylor Rahul,谢谢您的回答。当我应用你的代码时,我发现了一些错误。我是这方面的新手,我不知道该怎么处理这些东西。是否可以重定向到仅保留此javascript警报的其他页面。请帮忙。谢谢你能告诉我你得到了什么吗。。你可以更新你的问题。我们将一起解决这个问题。。JavaScript没有提供这个回调,所以这对您来说是有问题的。我已经更新了我的答案,并添加了几乎所有的声明。请现在查看@Taylor Rahul,获取错误无法找到名称“PresentalertConfig”。还可以在页面中添加的其他警报中获取错误。如果在聊天室中继续讨论,我将准确地分享这个问题,这将是非常棒的。对不起,我忘记在函数名之前添加这个。我再次更新了我的代码。请使用最新版本。如果你还有任何错误,请告诉我