Reputation: 2662
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
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