0

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?

2 Answers 2

2

Try this:

OData.read(request, this.readSuccessCallback.bind(this), this.errorCallback.bind(this));
Sign up to request clarification or add additional context in comments.

1 Comment

Hi yurzui, thanks for your answer. Your solution is working!
0

It seems to me that your readSuccessCallback is called, but that this has become undefined. This may be the case when you are working in strict mode (which I believe is the default mode from 1.8 up).

I can't test this here, but define your callback like so:

public readSuccessCallback(data, response) = (data, response) => {
  this.model.maktx = "Test3";
}

which should lead this to point to your actual instance.

1 Comment

Hi Roy, thanks for your answer. This syntax is not working. After the ) is { or ; expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.