Ionic 4. Alternative to NavParams

后端 未结 8 1644
灰色年华
灰色年华 2021-01-06 10:55

I am using ionic 4. It does not accept to receive data using navparams. Here is my sender page method:

  //private route:Router
  gotoFinalView(intent) {
            


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 11:19

    ionic 4 navigation with params

    sender page 1. import the following

    import {NavController} from '@ionic/angular';
    import { NavigationExtras } from '@angular/router';
    
    1. constructor(private navCtrl:NavController)
    2. sender page

    gotonextPage()

    gotonextPage()
    {
    let navigationExtras: NavigationExtras = {
              state: {
                user: 'name',
                parms:Params
              }
            };
            this.navCtrl.navigateForward('pageurl',navigationExtras);
    }
    

    4.Receiver Page

    import { ActivatedRoute, Router } from '@angular/router';
    constructor( private route: ActivatedRoute, private router: Router)
    {
    this.route.queryParams.subscribe(params => {
      if (this.router.getCurrentNavigation().extras.state) {
        this.navParams = this.router.getCurrentNavigation().extras.state.parms;
      }});
    }
    

提交回复
热议问题