I have to add an third party JavaScript plugin with callback function to an Angular JS application.
The JavaScript plugin provides a function like this:
thirdPartyFunction(parameter1, parameter2, parameter3, callback);
In the callback function I get the result that the plugin calculated.
The callback function looks like this:
callback(resultobject)
{ ... }
I want to display the result in my angular application. How can I get the resultobject in the $scope? It's not possible to rewrite the JavaScript plugin so far.
My idea is to provide a angular service like this one, but how should I implement the service?:
app.factory('myservice', function () {
function callback(resultobject) {
???
}
return {
getResult: function(parameter1, parameter2, parameter3) {
thirdPartyFunction(parameter1, parameter2, parameter3, callback);
return ???;
}
};
});