javascript - 如何在 Cordova 中使用 Angular 2 (Angular-CLI) 项目中的 JavaScript 文件

标签 javascript cordova angular angular-cli

当我构建 Angular-cli 项目时,它会生成许多我想在 Cordova 项目中使用的 Bundle.js 文件。问题是cordova不读取js文件。 js 文件位于 www 文件夹中,脚本标记位于 index.html 文件中。 有谁知道为什么cordova不读取js文件?

这是index.html文件

<!DOCTYPE html>
<html>
    <head>
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="icon" type="image/x-icon" href="favicon.ico">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
        <base href="/">
        <title>Test</title>
    </head>
    <body>
        <test-app>
            <div class="center-div center-text">
                Loading... <br /><br />
                <!--<img class="loading no-style" src="/images/loading.png">-->
                <i class="fa fa-spinner fa-spin fa-5x fa-fw"></i>
            </div>
        </test-app>
        <script type="text/javascript" src="inline.bundle.js"></script>
        <script type="text/javascript" src="styles.bundle.js"></script>
        <script type="text/javascript" src="scripts.bundle.js"></script>
        <script type="text/javascript" src="main.bundle.js"></script>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="scripts/platformOverrides.js"></script>
        <script type="text/javascript" src="scripts/index.js"></script>
    </body>
</html>

编辑:这个解决方案对我有用:

将其添加到 config.xml:

<access origin="*"/>
<access origin="tel:*" launch-external="yes"/>
<allow-navigation href="*"/>
<allow-navigation href="http://*/*"/>
<allow-navigation href="https://*/*"/>
<allow-navigation href="data:*"/>
<allow-intent href="*"/>

然后将基本 href 从 <base href="/"> 更改为至<base href=".">

最佳答案

我无法发表评论(没有足够的声誉),但我遇到了同样的问题,并在 Stackoverflow 中找到了解决方案。由于没有经过投票的答案,也没有对您的结论进行解释,因此我保留了我的解释的链接:

https://stackoverflow.com/a/39707190/6852181

请注意,您可以在使用 angular-cli 工具时通过参数 --base-href PATH 声明基本路径。这样您就不必手动更新任何内容,您可以在构建时使用 --base-href .

萨鲁2。

关于javascript - 如何在 Cordova 中使用 Angular 2 (Angular-CLI) 项目中的 JavaScript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40975476/

相关文章:

javascript - 未捕获的类型错误 : Cannot read property 'toString' of null

javascript - React Native 深层链接应用程序从后台打开

javascript - 如何将两个值绑定(bind)并获取到函数?

css - 如何在视口(viewport)中将一组 JQuery Mobile 单选按钮居中?

ios - js构建错误: Error: Your ios platform does not have Api.

javascript - 使用(更改)Angular 5 访问数组的每个部分

javascript - 未处理的异常:System.TimeoutException:请求 channel 在00:01:59.4579323之后等待答复时超时

android - 在 Android 4.4+ 上运行时如何忽略 Cordova App 的字体大小设置更改?

angular - Angular Material 中日期选择器的 A11yLabel 是什么?

angular - 类型 ClassB 中的属性 x 不可分配给基类型 ClassA 中的相同属性