Aka*_*Rao 14 javascript ionic2 angular
我尝试在ionic2的push方法中传递参数.像这样
this.nav.push(SecondPage, {
thing1: data1,
thing2: data2
});
Run Code Online (Sandbox Code Playgroud)
但有没有办法在pop()中传递参数.
Pra*_*ant 15
这就是我在离子3中实现它的方法,并且发现它更容易.
我们pop()的页面
this.navCtrl.getPrevious().data.thing1 =data1;
this.navCtrl.getPrevious().data.thing2 =data2;
this.navCtrl.pop();
Run Code Online (Sandbox Code Playgroud)
pop()后的页面:
public ionViewWillEnter() {
this.thing1 = this.navParams.get('thing1')|| null;
this.thing2 = this.navParams.get('thing2')|| null;
}
Run Code Online (Sandbox Code Playgroud)
akz*_*z92 14
我建议你使用Events.您所要做的就是在父页面上订阅一个事件,然后在传递所需数据的子项上发布事件:
// 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]);
});
Run Code Online (Sandbox Code Playgroud)
好像有| 请参阅文档参考|
pop(opts)接受一个类型参数object
所以
退一步
this.nav.pop({
thing1: data1,
thing2: data2
});
Run Code Online (Sandbox Code Playgroud)
并转到历史堆栈中的特定视图
this.nav.popTo(SecondPage, {
thing1: data1,
thing2: data2
});
Run Code Online (Sandbox Code Playgroud)
并转到堆栈的根
this.nav.popToRoot({
thing1: data1,
thing2: data2
});
Run Code Online (Sandbox Code Playgroud)
检索参数 (我想这应该可行。未经测试!)
export class SecondPage{
constructor(params: NavParams){
this.params = params;
console.log(this.params.get('thing1'));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16020 次 |
| 最近记录: |