我在Angular 4中有一个本地应用程序,它使用桌面浏览器上的localStorage来持久化数据。我在应用程序中使用AI中的WebViewer。
我知道localStorage不能在AI2中使用,需要使用WebViewString或任何其他数据存储。我还知道如何使用Javascript中的window.AppInventor检查应用程序是否在AI或桌面浏览器中运行。
我的问题是-如何使用Angular 4检查应用程序是否在AI中运行?这样我就可以将localStorage用于桌面,将WebViewString用于AI
我尝试在我的Angular代码中使用window.AppInventor,但得到一个错误
Property 'AppInventor' does not exist on type 'window'发布于 2018-05-30 14:12:12
找到了这个问题的答案:)
我需要在Typescript中获取Javascript窗口对象的引用。一旦我获得了引用,就像在Javascript中使用window对象一样。
https://juristr.com/blog/2016/09/ng2-get-window-ref/
有关获取本机窗口引用的更多详细信息,请查看上面的链接。一旦我们获得了引用,就可以像这样使用它
if (this.winRef.nativeWindow.AppInventor) {
this.persistData = JSON.parse(this.winRef.nativeWindow.AppInventor.getWebViewString());
} else {
this.persistData = JSON.parse(localStorage.getItem("floodPersist"));
}https://stackoverflow.com/questions/50588625
复制相似问题