Ionic Passing Data from Child to Parent Page

In Ionic, we can use NavController push method to sent data from parent to child page.
this.navCtrl.push(‘childPage’, { “ParentData“: parentdata });

If we want to send data from child to parent, then we can’t use NavController or NavParam to sent data back to the parent page.

We can use event class from ionic-angular. The Events is a publish-subscribe style event system for sending and responding to application-level events across your app.

Step 1: Define publishing event in a child pageĀ 

import { Events } from 'ionic-angular';
....
....

this.events.publish('employee:img', this.profileImg);

 

Step 2. In parent page, we have to create listen to the event in viewDidLoad() we will define listener event

ionViewDidLoad() {
	// Get data from child page
	this.event.subscribe('employee:img', (photo) => {
	this.profilePhoto = photo;
});