利用回调完成非父子组件间的传值
我的案列是在一个组件里使用ionic的ModalController模块创建一个小的modal,在modal里再触发创建modal,然后再push到另一组件
- 最开始的回调,也是最终执行的函数
let modal = this.modalCtrl.create(page, { data,call:(parm)=>{//page=>页面,data=>数据,call=>回调
console.log(parm);
this.delToPayList(parm);//这个是你最终要执行的函数
}}, {
cssClass: 'custom-modal2'//modal样式
});
this.modal = modal;
modal.present();//显示modal
- 在第二个modal中触发push
let modal = this.modalCtrl.create(smPage, data, {
cssClass: 'custom-modal2'
});
this.modal = modal;
modal.present();
this.navCtrl.push(Page,{//page=>组件,call=>回调
call: (pp)=>{
this.callPayMent(pp);
}
});
- 在另一个组件中接受push传过过来的数据
ngOnInit() {
this.isCanleWay = this.navParams.get('call');//isCanleWay 要声明=>public isCanleWay:any
}
fn(){
this.isCanleWay(this.orderNo);//在需要进行传值的方法里调用
}
- 一个大致的过程