I'm nidhin
I'm nidhin

Reputation: 2662

Dynamically creating and reading global variables

In my angular app, I'm using a framework to render html dynamically. I will call the below method to render the html

Presto.layout(layoutJson, contentJson , document.getElementById('contentArea'), this.callbackFunction);

This will fetch the contentJson and build the html as per the layoutJson and inject into the contentArea div. Once the rendering is complete, the callbackFunction will be triggered.

Issue

public callbackFunction(callbackID) { 
   this.anotherFunction(); // This will not work as the `this` is replaced with another object.
}

None of the functions in the component is available inside the call-back function. The this object inside the callback function contains data associated with the Presto js. Can I save the old this globally and get it inside the callback function.

Upvotes: 0

Views: 94

Answers (1)

Luca Taccagni
Luca Taccagni

Reputation: 1059

The problem is that the "binding" is missing in the callBack function, so try this:

Presto.layout(layoutJson, contentJson , document.getElementById('contentArea'), this.callbackFunction.bind(this));

Upvotes: 1

Related Questions