在Ionic中,可以使用NavController push方法将数据从父页发送到子页,this.navCtrl.push('childPage', { " ParentData " :
parentData -7D);
如果要将数据从子级发送到父级,就不能使用NavController或NavParam。
我们可以从ionic-angular使用事件类,
步骤1:在子页面中定义发布事件
import { Events } from 'ionic-angular';
....
....
this.events.publish('employee:img', this.profileImg);
步骤2.在父页面中,我们必须在viewDidLoad()中创建侦听事件,定义侦听器事件
ionViewDidLoad() {
// Get data from child page
this.event.subscribe('employee:img', (photo) => {
this.profilePhoto = photo;
});
相关文章