I have a handler defined like this in my typescript class
"handler": function (response) {
this.sendUserStatus();
},
But when i call this.sendUserStatus(); i am getting following error
Uncaught TypeError: this.sendUserStatus is not a function
How do i make this call this.sendUserStatus()?
Use an arrow function:
"handler": (response) => this.sendUserStatus()
Otherwise the this
context is lost if you use the function
keyword.
Also, be aware that you are using angular, and these kind of events are probably not patched by ngZone. You should re-enter the zone:
constructor(private ng: NgZone) {}
"handler": this.ng.run(() => (response) => this.sendUserStatus())