Ionic 4 Events not working in device but working on browser

前端 未结 1 1120
遥遥无期
遥遥无期 2021-01-28 05:27

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 eve

相关标签:
1条回答
  • 2021-01-28 05:54

    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'
    })
    export class EventsService {
    
    private fooSubject = new Subject<any>();
    
    constructor() { }
    
    
        publishLogin(data: any) {
            this.fooSubject.next(data);
        }
    
        receiveLogin(): Subject<any> {
            return this.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);
          })
    
    0 讨论(0)
提交回复
热议问题