Can´t add Bootstrap 4 in Angular 6

試著忘記壹切 提交于 2019-12-02 01:22:15

Delete "../node_modules/bootstrap/dist/css/bootstrap.min.css", in the Angular.json.

Try add this @import "~bootstrap/dist/css/bootstrap.css"; to your style.css file.

Ref: Styling Angular CLI v6 apps with Bootstrap

In the new version of angular, use node_modules/bootstrap/dist/css/bootstrap.min.css instead of ../node_modules/bootstrap/dist/css/bootstrap.min.css

So in angular.json file style attribute will look like

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

NOTE: if ng serve is already running then you may need to stop and run it again after doing the above changes. Happy coding :)

In the Angular 6 you can add bootstrap to two files:

  1. Inside the angular.json:

    "styles": [
        "./node_modules/bootstrap/dist/css/bootstrap.min.css",
        "src/styles.css"
    ]
    
  2. Inside the angular.json:

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

    /* You can add global styles to this file, and also import other style files */
    @import "~bootstrap/dist/css/bootstrap.css";
    

Note: If you use the first or second way, it's needed to cancel the running application, that means, if ng serve is active you must exit the app with Ctrl + C, but in the third way, it's not needed to cancel the application.

If the project has a test runner like Karma the Angular.json file has two styles property:

1- projects -> projectName -> architect -> build -> options

2- projects -> projectName -> architect -> test -> options

Maybe you just change styles in the test section and the build section has old styles.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!