Ionic 4. Alternative to NavParams

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

    This is how I solved my problem:

    I created a Service with a setter and getter methods as;

    import { Injectable } from "@angular/core";
    
    @Injectable({
      providedIn: "root"
    })
    export class MasterDetailService {
      private destn: any;
      constructor() {}
    
      public setDestn(destn) {
        this.destn = destn;
      }
    
      getDestn() {
        return this.destn;
      }
    }
    

    Injected the Service and NavController in the first page and used it as;

      gotoFinalView(destn) {
        this.masterDetailService.setDestn(destn);
        this.navCtrl.navigateForward("destn-page");
      }
    

    Extracted the data at the final page by;

    constructor(
        private masterDetailService: MasterDetailService
      ) {
        this.destination = this.masterDetailService.getDestn();
      }
    

提交回复
热议问题