[SOLVED] notificationEvents.emit Error

Hi there,

has anyone managed to successfully emit an event from a tabbed view?

I keep getting this error:
Uncaught ReferenceError: notificationEvents is not defined

when trying to emit an event from one of my views after an ajax request.

the code in the success part of the ajax request is as follows:

notificationEvents.emit(‘notificationReceived’, {
zone: ‘#mainToolbar’,
type: ‘.watching’,
count: data.fav_count,
});

and in my app.js

const notificationEvents = new Framework7.Events();

notificationEvents.on(‘notificationReceived’, function (notification) {
$$(notification.zone).find(notification.type).append(’’+notification.count+’’);
});

I can emit events from within the app.js but I would like to from any view in my app.

thanks in advance

app.js:
data : {
notificationEvents : new Framework7.Events();
}

in router component:
this.$root.notificationEvents.on(…)
or
this.$root.notificationEvents.emit(…)

in app.js (in app):

this.data.notificationEvents.on(…)
or
this.data.notificationEvents.emit(…)

1 Like

I cant thank you enough, that worked perfectly.

instead of this, I had to use app.data.notificationEvents in app.js but asides from that, all is well.