Events and handler


#1

Hi,

Does anyone know why I can’t access this.navParams from inside an event handler in the following code?

export class MyPage {
    aProperty: any;
    constructor(navParams: NavParams) {
    }
    onViewDidLoad() {
        this.events.subscribe('event:topic', this.eventHandler);
    }
    eventHandler(data) {
        console.log(this.navParams);
    }
}

I can access aProperty but this.navParams returns null. Is there anything i’ve done wrong?

Many thanks.


#2

I’ve got it working by using arrow function by redeclaring

eventHandler = (data)  => {
    console.log(this.navParams);
}

It looks inconsistent with the rest of the code but that will do for now.