Registering Moodle Mobile event observers in plugins

Re: Registering Moodle Mobile event observers in plugins

by Dani Palou -
Number of replies: 0
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi David,

sorry for the delay in answering, I was on leave.

To have access to CONTENT_OTHERDATA and the block component itself you should add the event in the javascript code returned by your "method", not in the "init" one. Please notice that you should stop listening for events if the component is destroyed. For example (I haven't tested this code):

var that = this;
var observer = this.CoreEventsProvider.on('courses_my_courses_updated', function(e) {
    // You can access that.CONTENT_OTHERDATA or whatever you want in here. }, this.CoreSitesProvider.getCurrentSiteId());
this.ngOnDestroy = function() {
    observer.off(); };

Cheers,
Dani