angular2 ng-cli:无法将index-bootstrap添加到index.html

时间:2016-11-30 14:43:42

标签: html twitter-bootstrap

我最近使用ng-cli创建了一个angular2 web应用程序。我正在尝试将Twitter-bootstrap(我用npm安装)添加到我的index.html文件中。由于某种原因,即使路径正确,它似乎也找不到引导程序。我错过了什么吗? ng-cli是否在其他地方移动引导程序?

我的代码:

<link rel="stylesheet" href="./../node_modules/bootstrap/dist/css/bootstrap.min.css" type="text/stylesheet">

1 个答案:

答案 0 :(得分:1)

Angular cli无法按照您的方式运作。它添加如下的第三方库。

  1. 使用NPM添加安装库

    npm install bootstrap @ next

  2. 在angular-cli.json的apps [0] .scripts和apps [0] .styles属性中添加脚本和样式文件。喜欢

        apps": [
        {
          "root": "src",
          "outDir": "dist",
          ......
    
          "styles": [
            "../node_modules/bootstrap/dist/css/bootstrap.css",
            "styles.css"
          ],
          "scripts": [
            "../node_modules/bootstrap/dist/js/bootstrap.js",
            ],
          "environments": {
            "source": "environments/environment.ts",
            "dev": "environments/environment.ts",
            "prod": "environments/environment.prod.ts"
          }
        }
      ],
    
  3. 添加后像这样。它会将所有文件添加到index.html