Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48983

Ionic 5 Events pass data while switching page

$
0
0

Yo devs,
I’m struggle with passing some data through Events while transition from one page to another:

export class Page1 implements OnInit {
  constructor(
    public events: EventsService
  ) {
    events.subscribe('appointment:test', (data: any) => {
        console.log(data)
    });
  }

:point_up: Of course I tried to put subscription inside ngOnInit and ionViewDidEnter

export class Page2 implements OnInit {
  constructor(
    public events: EventsService
  ) {}

  goBack() {
    let data = { test: 'test' }
    this.events.publish('appointment:test', data);
    this.navCtrl.navigateBack('page1');
  }

:point_up: Here I also tried to put publishing in ionViewDidLeave

I know that I can pass data through navigation but that way worked in previous Ionic version, would be nice to know why it not works anymore :slight_smile:

Also I’m sure that Events are working, when I publish while being on the same page works perfectly fine…

Thanks for any suggestion :bowing_man:

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 48983

Trending Articles