I have the following code, but when the onChange is triggered it gives me an error. (Uncaught TypeError: Cannot set property 'myVar' of undefined)
import { inject } from 'aurelia-framework';
import { ObserverLocator } from 'aurelia-framework';
@inject(ObserverLocator)
export class myClass{
field= "";
myVar = 0;
constructor(observerLocator) {
this.field= "";
var subscription = observerLocator
.getObserver(this, 'field')
.subscribe(this.onChange);
}
onChange(){
this.myVar +=1;
}
}