【问题标题】:how to install a module with npm in angular 1如何在角度 1 中安装带有 npm 的模块
【发布时间】:2016-09-29 05:00:03
【问题描述】:

我正在尝试使用 npm 安装引导程序。我跑了:

npm install angular-ui-bootstrap

并且成功地将模块安装在node_modules 文件夹中。问题是我似乎无法引用 index.html 中的文件。我输入以下行:

<script src="/node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js"></script>

但它返回 404。我有 3 个问题:

  1. 我是否引用了正确的文件
  2. 如何将文件包含在 index.html 中
  3. 如果我在 html 中包含该文件,是否足以消除我遇到的另一个错误:

    Error: [$injector:modulerr] Failed to instantiate module ui.bootstrap due to:
    Error: [$injector:nomod] Module 'ui.bootstrap' is not available!
    

这是文件结构:

Project
    -app
        -index.html
    -node_modules
        -angular-ui-bootstrap
            -dist
                -ui-bootstrap.js

【问题讨论】:

  • 你能提供node_modules/附近的文件结构吗?
  • 是的,我刚刚添加了它。
  • 尝试将../ 添加到您的参考文献的开头。您需要移出app/ 目录。
  • 使用&lt;script src="../node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js"&gt;&lt;/script&gt;
  • @Aeolingamenfel 谢谢,这就是我的想法,但它不起作用。我得到完全相同的错误

标签: angularjs npm angular-bootstrap


【解决方案1】:

只需从 &lt;script src="/node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js"&gt;&lt;/script&gt; 中删除 / 像这样:

<script src="node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-17
    • 2014-11-12
    • 1970-01-01
    • 2019-03-08
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多