Search code examples
ionic-frameworkionic4

Ionic 4 Pass parameter to another page


Please help how to pass param to another page in ionc 4?

As the push and navparam function seen not working anymore in ionic4.

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


Solution

  • 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) 
        }
    }