Saylim Saylim - 4 months ago 63
TypeScript Question

Uncaught TypeError: Cannot set property 'model' of undefined

I have a special problem with a callback method and local variable:

export class Test {

model: Article;

onKeyEnter(value: string) {
this.model.maktx = "Test1";

//This is not working
this.find(value);

// Direct call is working
//this.readSuccessCallback(null, null);
}

find(nr) {

[..other stuff]

OData.read(request, this.readSuccessCallback, this.errorCallback);
}

readSuccessCallback(data, response) {
this.model.maktx = "Test2";
}
}


The
"Test2"
value is set correctly when I call
readSuccessCallback
direct from
onKeyEnter


If the
readSuccessCallback
method is called from the
OData.read

(SAP Kapsel 3rd Party) an exception occured:


Uncaught TypeError: Cannot set property 'model' of undefined.


Has anyone got an idea what is happening? I don't know exactly what
OData.read
is doing but it seems that I am not coming back to where I was leaving?

Answer

Try this:

OData.read(request, this.readSuccessCallback.bind(this), this.errorCallback.bind(this));
Comments