How to pass parameters in pop method of ionic2

后端 未结 8 1584
隐瞒了意图╮
隐瞒了意图╮ 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

    I suggest you use Events. All you have to do is to subscribe to an event on the parent page and then publish the event on the child passing the data you want:

    // taken from the docs
    import { Events } from 'ionic-angular';
    
    constructor(public events: Events) {}
    
    // first page (publish an event when a user is created)
    function createUser(user) {
      console.log('User created!')
      events.publish('user:created', user);
    }
    
    // second page (listen for the user created event)
    events.subscribe('user:created', (userEventData) => {
      // userEventData is an array of parameters, so grab our first and only arg
      console.log('Welcome', userEventData[0]);
    });
    

提交回复
热议问题