Provide general JavaScript function with Angular?

78 Views Asked by At

is there a way to provide a global JavaScript function in an Angular App, which can be called by non-Angular JS code?

Background: Our Angular app is running inside a webview of a Qt application. Now we are investigating possibilities to provide an API, so that the Qt application can call functions of the Angular app.

1

There are 1 best solutions below

0
IAfanasov On

Any front-end javascript code (including Angular) has access to global objects window and document. You can add any function or property into those 2.

window.myAPI = {
   doIt: function () {...},
   doItBetter: function () {...}
}

I'm not familiar with QT WebView, so I can not help you to understand if you can get access window or document from the QT code. I would rather expect you can.

As another solution - https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage. Don't know if QT code can react to those messages.