Skip to content Skip to sidebar Skip to footer

Ionic 4 Events Not Working In Device But Working On Browser

I'm using '@ionic/angular': '^4.11.10' I'm trying to display the tabs in ion-tabs in ion-tab-bar depending on whether an event was emitted. I have an *ngIf for conditional renderin

Solution 1:

To update Data from one page to other we used Events library. but events are no longer available in ionic 5. blow is the solution. run command:

ionic generate service events        // this will create events provider

copy paste blow code.

import { Injectable } from'@angular/core';
import {Subject} from'rxjs';

@Injectable({
  providedIn: 'root'
})
exportclassEventsService {

private fooSubject = newSubject<any>();

constructor() { }


    publishLogin(data: any) {
        this.fooSubject.next(data);
    }

    receiveLogin(): Subject<any> {
        returnthis.fooSubject;
    }
}

From Page A: import your service initialize it in constructor //

constructor(public events: EventsService){}

and publish event E.g.

this.events.publishLogin(yourDataVariable);

Receive it in Page B: import your service initialize it in constructor //

constructor(public events: EventsService){}

this.events.receiveLogin().subscribe((res:any)=>{
        console.log(res);
      })

Post a Comment for "Ionic 4 Events Not Working In Device But Working On Browser"