nativescript-webview-interface
nativescript-webview-interface copied to clipboard
How to get this work with angular app in webview?
I have an angular web app. For some reason, I have to get it work within nativescript app.
I see your demo run a local html in webview with your plugin enabled. However, it is suggested to load a module inside angular rather than using
I also tried to accomplish this with Angular + Typescript
What I did was to create a d.ts file to export the class and made the JS file available inside my bundle for scripts. On the component where I wanted to enable the comunication, was just
let wbInterface: NSWebViewInterface.WebViewInterface = (<any>window).nsWebViewInterface;
I ended up just porting it to typescript for our angular app then imported it similarly @mbondoso. Uploaded it as a gist here if anyone wants to take the same path. I also added an off method to remove event listeners.
// setup global NsWebviewInterface
const nsWebViewInterface = new NsWebViewInterface();
(window as any).nsWebViewInterface = nsWebViewInterface;
@Component({
//...
Just updated everything in project (tns to 3.4.0, angular to 5, etc) and now webview is not being displayed. Any ideas?
I see this in console: JS: ERROR TypeError: Cannot read property 'natiescriptwebviewinterface' of undefined
I want to call
const nsWebViewInterface = new NsWebViewInterface(); (window as any).nsWebViewInterface = nsWebViewInterface;
thanks!
Now, how do I make a function that will be called from ns app?