在 NativeScript 应用程序中加载本地 HTML/JavaScript/CSS [英] Load Local HTML/JavaScript/CSS Inside NativeScript App

查看:32
本文介绍了在 NativeScript 应用程序中加载本地 HTML/JavaScript/CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于使用 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/Image 导入 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆