# Ionic 4 events not working

**URL:** <https://forum.ionicframework.com/t/ionic-4-events-not-working/137099>\
**Category:** Ionic Framework\
**Created:** [August 2, 2018, 9:30am UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099 "2018-08-02T09:30:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonmikelm](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jonmikelm](https://forum.ionicframework.com/u/jonmikelm)\
**Post date:** [August 2, 2018, 9:30am UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099/1 "2018-08-02T09:30:28Z")

</div>

According to a comment in the post announcing Ionic beta 4, events should work the same way as previus versions. The only required change would be the import, @ionic/angular instead of ionic-angular.

> [@Announcing Ionic 4 beta!](https://forum.ionicframework.com/t/announcing-ionic-4-beta/136262/24):
>
> Events are still in the process of being documented, but they are there in @ionic/angular and work the same As for the headers, we’ll review what needs to change and consider it for a future release.

But I haven’t yet managed to make them work. I have tested the most simple use case:

I subscribe to an event in ngOnInit method, and publish that same event when clicking a button. But nothing seems to happen.

```auto
import { Events } from '@ionic/angular';
export class LoginPage implements OnInit {
  constructor(public events: Events) { }
  ngOnInit(){
    this.events.subscribe('testevent', (data) => {
      console.log('testevent');
      console.log(data);
    });
  }
  publishEvent(){
    console.log('shouldPublishEvent');
    this.events.publish('testevent', {key: 'value'});
  }
}

```

Am I missing something?

---

<div class="post-metadata">

**Author:** ![jonmikelm](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jonmikelm](https://forum.ionicframework.com/u/jonmikelm)\
**Post date:** [August 2, 2018, 9:47am UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099/2 "2018-08-02T09:47:04Z")

</div>

I have just noticed that beta 1 was released yesterday.

Events work as expected after updating to beta 1.

---

<div class="post-metadata">

**Author:** ![peterwb](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@peterwb](https://forum.ionicframework.com/u/peterwb)\
**Post date:** [August 2, 2018, 12:53pm UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099/3 "2018-08-02T12:53:58Z")

</div>

Thanks for the info. I had same issue and verified Events now properly working in @ionic/angular 4.0.0-beta.1

npm i @ionic/angular@latest

---

<div class="post-metadata">

**Author:** ![karvanj](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@karvanj](https://forum.ionicframework.com/u/karvanj)\
**Post date:** [September 16, 2018, 5:35am UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099/4 "2018-09-16T05:35:34Z")

</div>

Is anyone having troubles with events beta 8? I tried importing into a page (not lazy loaded) but get a no provider error as below:

 ![16%20pm](https://global.discourse-cdn.com/ionicframework/original/3X/0/9/093ff9b066687966af05138e7aadd2cd7e346049.png)

Do I need to import anything into my app.module to make this work? My Ionic Info below

```auto
Ionic:

   ionic (Ionic CLI) : 4.1.2 (/usr/local/lib/node_modules/ionic)
   Ionic Framework : @ionic/angular 4.0.0-beta.8
   @angular-devkit/core : 0.7.5
   @angular-devkit/schematics : 0.7.5
   @angular/cli : 6.1.5
   @ionic/ng-toolkit : 1.0.8
   @ionic/schematics-angular : 1.0.6

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms : none
   Cordova Plugins : no whitelisted plugins (1 plugins total)

System:

   NodeJS : v8.9.4 (/usr/local/bin/node)
   npm : 6.4.1
   OS : macOS High Sierra

```

---

<div class="post-metadata">

**Author:** ![karvanj](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@karvanj](https://forum.ionicframework.com/u/karvanj)\
**Post date:** [September 16, 2018, 6:21am UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099/5 "2018-09-16T06:21:03Z")

</div>

Ignore the above I had imported

`import { Events } from 'ionic-angular'`

not as

`import { Events } from '@ionic/angular';`

---

<div class="post-metadata">

**Author:** ![Thesurya9](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/thesurya9/32/117460_2.png) [@Thesurya9](https://forum.ionicframework.com/u/Thesurya9)\
**Post date:** [March 25, 2019, 5:05pm UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099/7 "2019-03-25T17:05:26Z")

</div>

did you find the solution ? if yes then please share it.  
I need it to update the left side menu bar. which is showing currently logged in user name.

---

<div class="post-metadata">

**Author:** ![ESTEI9](https://avatars.discourse-cdn.com/v4/letter/e/bc79bd/32.png) [@ESTEI9](https://forum.ionicframework.com/u/ESTEI9)\
**Post date:** [March 26, 2019, 6:19pm UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099/8 "2019-03-26T18:19:17Z")

</div>

I have found that in pretty much all situations if I need to pass data, it’s better to use a service as a go-between. Store the data in a service variable and then retrieve it where you need it. That’s what I did for a custom menu and it’s options. For your application @Thesurya9, that’s probably the best solution.

---

<div class="post-metadata">

**Author:** ![plabonasad](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/plabonasad/32/128321_2.png) [@plabonasad](https://forum.ionicframework.com/u/plabonasad)\
**Post date:** [April 11, 2019, 7:17am UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099/9 "2019-04-11T07:17:17Z")

</div>

File name: `app.component.ts`

```auto
user_name = ' ';

constructor(
        private platform: Platform,
        private splashScreen: SplashScreen,
        private statusBar: StatusBar,
        private router: Router,
        private menuCtrl: MenuController,
        private events: EventService
    ) {
this.events.dispatcher.subscribe(response => {
            if (response.auth) {
                this.user = response.auth;
                if (this.user.someting) {
                    this.someting = this.authService.base_url + this.user.someting.url;
                }
            }
            else {
                this.user_name = ' ';
            }
        });
    }

```

---

<div class="post-metadata">

**Author:** ![nuruddinba691](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nuruddinba691](https://forum.ionicframework.com/u/nuruddinba691)\
**Post date:** [April 14, 2019, 9:37pm UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099/10 "2019-04-14T21:37:59Z")

</div>

I have same issued, Did you fix it @jonmikelm ?

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:26pm UTC](https://forum.ionicframework.com/t/ionic-4-events-not-working/137099/11 "2021-07-19T21:26:16Z")

</div>

Closed on July 19, 2021, 9:26pm UTC


