I am trying to triger an event from a provider/service
to app.component.ts
.
Are there differences in behaviour of these two event listener
codes?
In my case it is present in app.component.ts
file to listen to even trigered from another service.
The 'events' is variabel of type 'Events' imported from 'ionic-angular'.
1. app.component.ts -
ngOnInit(){
this.events.subscribe('update-menu-title', (userInfo) => { // listener for "update-menu-title" event
// Usage of 'userInfo'
})
}
2. app.component.ts -
ngOnInit(){
this.getUserInfo();
}
getUserInfo(){
this.events.subscribe('update-menu-title', (userInfo) => { // listener for "update-menu-title" event
// Usage of 'userInfo'
})
}
This is how I am trigerring event from another provider/service
.
this.events.publish('update-menu-title', this.currentUser); // Update menu title
In my case the 1st
way is working for all builds/emulates ionic cordova build/emulate android --prod
.
But the 2nd
way is only working on non-production builds ionic cordova build/emulate android
.
But both codes work same in browser(s).
I can elaborate more in details what I am trying to achieve and how I have arranged my codes to do so. But that will be very long question.
Ionic info details -
@ionic/cli-utils : 1.10.2
ionic (Ionic CLI) : 3.10.3
global packages:
Cordova CLI : not installed
local packages:
@ionic/app-scripts : 2.1.3
Cordova Platforms : android 6.2.3 ios 4.4.0
Ionic Framework : ionic-angular 3.6.0
System:
Android SDK Tools : 26.0.2
Node : v8.1.3
npm : 5.3.0
OS : Windows 10