Ionic 4. Alternative to NavParams

后端 未结 8 1685
灰色年华
灰色年华 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:26

    Send data with Router service and extract with global variable, history

    //sender component

      // private router: Router
      nextPage() {
        this.router.navigate(['history'],
          { state: [{ name: "covid-19", origin: "china" },{ name: "ebola", origin: "us" }] }
        )
      }
    

    //receiver page

      ngOnInit() {
      let data = history.state;
      console.log("data-->",data);
    // ** data** 
    //0:{name: "covid-19", origin: "china"} 1: {name: "ebola", origin: "us"} navigationId: 2
      }
    

提交回复
热议问题