【问题标题】:Angular 6 add jquery, popper and bootstrap jsAngular 6 添加 jquery、popper 和 bootstrap js
【发布时间】:2018-09-27 12:33:51
【问题描述】:

我正在使用 angular 6 和 sass bootstrap 项目,我正在尝试在 angular.json 中添加 jquery、popper 和 js

我在 angular.json 中的代码是:

"styles": [
          "src/styles.scss"
        ],
        "scripts": [
          "../node_modules/jquery/dist/jquery.min.js",
          "../node_modules/popper.js/dist/popper.min.js",
          "../node_modules/bootstrap/dist/js/bootstrap.min.js"
        ]

我也试过这个:

 "styles": [
          "src/styles.scss"
        ],
        "scripts": [
          "./node_modules/jquery/dist/jquery.js",
          "./node_modules/popper.js/dist/popper.js",
          "./node_modules/bootstrap/dist/js/bootstrap.js"
        ]

但切换和下拉菜单对我不起作用。

【问题讨论】:

  • 只添加script标签下的css文件
  • 不起作用。我需要添加脚本依赖项以使一切正常
  • 你是否停止并再次运行ng serve进行编译?
  • 我做了但没用。在 Angular 6 中添加 js 的最佳方法是什么?

标签: angular twitter-bootstrap


【解决方案1】:
 npm install bootstrap to install boostrp
 npm install jquery to install jquery and add path under the 'build' inside 
 angular.json

"styles": [
          "src/styles.css", "node_modules/bootstrap/dist/css/bootstrap.min.css"
        ],
"scripts": ["node_modules/bootstrap/js/jquery.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"]

Please verify the file inside the node_modules.

【讨论】:

  • 这是我当前的版本:“styles”:[“src/styles.scss”],“scripts”:[“node_modules/jquery/dist/jquery.min.js”,“node_modules/popper” .js/dist/popper.min.js”, “node_modules/bootstrap/dist/js/bootstrap.min.js”]
  • 请提供您的 angular.json 文件
  • 根据您的 json 文件,没有 "styles": [ "src/styles.scss" ], "scripts": [ "node_modules/bootstrap/dist/css/bootstrap.min.css" ]
猜你喜欢
  • 1970-01-01
  • 2020-03-30
  • 2018-01-20
  • 1970-01-01
  • 1970-01-01
  • 2018-05-03
  • 2018-10-26
  • 1970-01-01
  • 2018-11-19
相关资源
最近更新 更多