首页 > 解决方案 > Ionic 4 将参数传递到另一个页面

问题描述

请帮助如何将参数传递到ionc 4中的另一个页面?

正如在 ionic4 中看到的 push 和 navparam 函数不再起作用一样。

https://medium.com/@muthudevendra/ionic-sharing-data-between-pages-8d0412cb8f58

标签: ionic-frameworkionic4

解决方案


Page1.ts

public country: string;
  public email: string;
  public password: string;   

constructor(public nav: NavController) {}

goToAboutPage() {
    let params: any = {
      country: this.country,
      email: this.email,
      password: this.password
    }
    this.nav.navigateForward('/identity', { state: params }); // params to pass object/array
  }

Page2.ts

constructor(public router: Router){
if (router.getCurrentNavigation().extras.state) {
      const params = this.router.getCurrentNavigation().extras.state;
console.log(params.email)
console.log(params.password)
console.log(params.country) 
    }
}

推荐阅读