Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can´;t在6中添加引导4_Javascript_Css_Angular_Twitter Bootstrap_Angular6 - Fatal编程技术网

Javascript Can´;t在6中添加引导4

Javascript Can´;t在6中添加引导4,javascript,css,angular,twitter-bootstrap,angular6,Javascript,Css,Angular,Twitter Bootstrap,Angular6,当我尝试使用添加最新的引导版本时出现问题 npm install bootstrap 在那之后,我尝试运行它时收到一条错误消息 ng serve --open 我在angular.json中添加了引导 像这样 "styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.css" ], 错误消息是 ERROR in multi .

当我尝试使用添加最新的引导版本时出现问题

npm install bootstrap
在那之后,我尝试运行它时收到一条错误消息

ng serve --open
我在angular.json中添加了引导

像这样

"styles": [
          "../node_modules/bootstrap/dist/css/bootstrap.min.css",
          "src/styles.css"
        ],
错误消息是

    ERROR in multi ../node_modules/bootstrap/dist/css/bootstrap.min.css ./src/styles.css
Module not found: Error: Can't resolve '...\node_modules\bootstrap\dist\css\bootstrap.min.css' in '...'
为什么我会收到错误消息?

删除Angular.json中的“./node\u modules/bootstrap/dist/css/bootstrap.min.css”,

尝试添加这个
@import“~bootstrap/dist/css/bootstrap.css”到您的style.css文件


参考:

在angular的新版本中,使用节点模块/bootstrap/dist/css/bootstrap.min.css而不是。/node\u模块/bootstrap/dist/css/bootstrap.min.css

因此,在angular.json中,文件样式属性如下所示

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

注意:如果ng serve已在运行,则您可能需要停止并在执行上述更改后再次运行。快乐编码:)

Angular 6中,您可以将引导添加到两个文件中:

  • angular.json中:

    "styles": [
        "./node_modules/bootstrap/dist/css/bootstrap.min.css",
        "src/styles.css"
    ]
    
    "styles": [
        "node_modules/bootstrap/dist/css/bootstrap.min.css",
        "src/styles.css"
    ]
    
    /* You can add global styles to this file, and also import other style files */
    @import "~bootstrap/dist/css/bootstrap.css";
    
  • angular.json中:

    "styles": [
        "./node_modules/bootstrap/dist/css/bootstrap.min.css",
        "src/styles.css"
    ]
    
    "styles": [
        "node_modules/bootstrap/dist/css/bootstrap.min.css",
        "src/styles.css"
    ]
    
    /* You can add global styles to this file, and also import other style files */
    @import "~bootstrap/dist/css/bootstrap.css";
    
  • style.css中:

    "styles": [
        "./node_modules/bootstrap/dist/css/bootstrap.min.css",
        "src/styles.css"
    ]
    
    "styles": [
        "node_modules/bootstrap/dist/css/bootstrap.min.css",
        "src/styles.css"
    ]
    
    /* You can add global styles to this file, and also import other style files */
    @import "~bootstrap/dist/css/bootstrap.css";
    
  • 注意:如果使用第一种或第二种方式,则需要取消正在运行的应用程序,也就是说,如果ng serve处于活动状态,则必须使用
    Ctrl+C
    退出应用程序,但在第三种方式中,不需要取消应用程序


    如果项目具有类似Karma的测试运行程序,Angular.json文件具有两种样式属性:

    1-项目->项目名称->架构师->构建->选项

    2-项目->项目名称->架构师->测试->选项


    也许您只是在测试部分更改了样式,而构建部分使用了旧样式。

    在angular中,我们必须添加我们安装的引导的方向。
    这意味着使用角度引导的步骤如下。

    1. npm install bootstrap
    
    然后我们必须在angular.json中添加路径,如下所示

    "styles": [
                  "src/styles.css",
                  "node_modules/bootstrap/dist/css/bootstrap.css"
                ]
    

    您安装了jquery吗?