Ionic 2 passing tabs NavParams to tab

前端 未结 5 633
名媛妹妹
名媛妹妹 2020-12-04 23:43

I\'m starting out on creating my first app using Ionic 2 and through a lot of trial and error have got to a point where no number of Google searching can find anything to

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 00:22

    There is no direct way to pass Params in Tab-Pages that I know of.

    I think you could play around with the NavController to make it work.

    A neat workaround is to put the parameter into an injected service: app/services/params.js:

    import {Injectable} from 'angular2/core';
    
    @Injectable()
    export class Params{
        constructor(){
            console.log("Params()");  
            this.params={};
        }
    }
    

    and in the controller:

        import {Params} from '../../services/params'
    
        @Page({
          templateUrl: 'build/pages/home/home.html',
        })
        export class XYPage{
    
        constructor(nav: NavController,platform: Platform, params: Params) {
           console.log("XYPage()",this);
           console.log("XYPage()", params.params);
           params.params={id="001"};
    

    dont forget to inject the service in your @App

提交回复
热议问题