How to pass parameters in pop method of ionic2

后端 未结 8 1578
隐瞒了意图╮
隐瞒了意图╮ 2021-02-04 07:04

I tried passing parameters in push method of ionic2. like this

this.nav.push(SecondPage, {
    thing1: data1,
    thing2: data2
});

but is ther

相关标签:
8条回答
  • 2021-02-04 07:55

    UPDATE: IT WAS SUPPOSED TO WORK, BUT IT DOES NOT


    Seems like there is |See Doc Reference|

    pop(opts) takes one parameter of type object

    so

    to go one step back

    this.nav.pop({
        thing1: data1,
        thing2: data2
    });
    

    and to go to a specific view in the history stack

    this.nav.popTo(SecondPage, {
        thing1: data1,
        thing2: data2
    });
    

    and to go to root of the stack

    this.nav.popToRoot({
        thing1: data1,
        thing2: data2
    });
    

    To retrieve the params (I guess this should work. untested!)

    export class SecondPage{
     constructor(params: NavParams){
       this.params = params;
    
       console.log(this.params.get('thing1'));
     }
    }
    
    0 讨论(0)
  • 2021-02-04 07:56

    Currently, I believe that there is no way of accomplishing this.

    There is a Github issue for it though, that has got some great discussion on it by the Ionic core team. It sounds like they have added it to the Ionic 2 roadmap, too! The Github issue also has some proposed work-arounds, such as adding the ParentPage to the NavParams going to the ChildPage, but it is all quite a bit hacky.

    0 讨论(0)
提交回复
热议问题