在NativeScript应用程序中加载本地HTML/JavaScript/CSS [英] Load Local HTML/JavaScript/CSS Inside NativeScript App
问题描述
对于使用Angular的NativeScript iOS和Android应用程序,如何在WebView内加载具有JS和CSS引用的本地存储的html文件?我可以显示WebView,但是由于找不到文件中的src,因此出现找不到文件的错误.
With a NativeScript iOS and Android app using Angular, how do I load, inside of a WebView, a locally stored html file that has JS and CSS references? I am able to display the WebView but I get the error that the file is not found because I do not know where to point the src from my component.
目前,我在src/assets中有文件,并且其中有index.html
Currently I have the files inside src/assets and in there is the index.html
在应用程序中是否存在更合适的位置来存储这些文件?有没有比WebView更好的显示方式了?如何引用此文件作为WebView的源?
Is there a more appropriate place to store these files within the app? Is there a better way to display this than a WebView? How do I reference this file as the source of a WebView?
我还将需要知道如何引用应用下载的文件. iOS和Android在哪里将应用程序中下载的文件存储在哪里?如何从WebView引用这些文件?
I will also be needing to know how to reference a file the app downloads. Where does iOS and Android store downloaded files from within the app? How do i reference these files from my WebView?
谢谢.
推荐答案
在将本地JS/CSS/图像导入WebView时,必须使用绝对路径.这是游乐场示例.与给定的示例不同,如果您要加载与应用程序打包在一起的文件,则只需使用应用程序目录而不是具有正确的文件路径.
You have to use absolute path while importing local JS / CSS / Image into WebView. Here is a Playground sample. Unlike the given example if you want to load files those are packed with app, simply use app directory instead with right path to file.
这篇关于在NativeScript应用程序中加载本地HTML/JavaScript/CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!