angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Bootstrap styles not loading

Open Harsangeet opened this issue 9 years ago • 45 comments

Hi,

I followed the steps for Global Library Installation https://github.com/angular/angular-cli#global-library-installation

  1. Installed [email protected] npm install bootstrap --save

  2. Then added the needed script files to to apps[0].scripts in angular-cli.json file:

 "scripts": [
    "../node_modules/bootstrap/dist/js/bootstrap.js"
    ],

and the Bootstrap CSS to the apps[0].styles array:

"styles": [
    "styles.css",
    "../node_modules/bootstrap/dist/css/bootstrap.css"
    ],
  1. Restarted ng serve

But the bootstrap styles are not loading

OS- Windows 7 Enterprise

angular-cli: 1.0.0-beta.21 node: 6.9.1 os: win32 x64

Harsangeet avatar Dec 05 '16 19:12 Harsangeet

Okay

On Wed 2 May, 2018, 2:06 AM irfanakbar47, [email protected] wrote:

Restart npm server

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/3411#issuecomment-385782090, or mute the thread https://github.com/notifications/unsubscribe-auth/AYVbk57P9H1m-pwjj_ClfjoMvHXUa6onks5tuMdGgaJpZM4LEpPr .

nadyscoolcodes avatar May 02 '18 02:05 nadyscoolcodes

restart the application using ng serve

STEPHINRACHEL avatar May 08 '18 09:05 STEPHINRACHEL

@alextait1 Works like a charm. Thank you so much :)

Yi98 avatar Jun 18 '18 05:06 Yi98

manojsgh solution works for me, I was trying the filipesilva solution but wihout results.

zahasoftware avatar Jul 28 '18 21:07 zahasoftware

I ran into the same issue,Bootstrap was not loading with Angular 6, no matter how I tried to import , finally solved by downgrading bootstrap 4 to 3

francesfang avatar Aug 03 '18 18:08 francesfang

add to styles.css @import "~bootstrap/dist/css/bootstrap.min.css";

alalicon577 avatar Sep 08 '18 20:09 alalicon577

I can confirm that this issue is because of bootstrap 4. I am using angular 6 and was trying to include bootstrap v4 it wasn't showing up and then I downgraded to bootstrap v3 and it works like a charm. Simply use the command npm install bootstrap@3 --save to downgrade to bootstrap v3

yawningphantom avatar Sep 09 '18 07:09 yawningphantom

try removing single dot (.). See below. This worked for me. "./node_modules/bootstrap/dist/css/bootstrap.min.css"

echosanjeet avatar Sep 10 '18 11:09 echosanjeet

Ran into the same issue and had to downgrade to version 3 of bootstrap and it worked.

navgag33 avatar Oct 14 '18 17:10 navgag33

I also have the same issue, however I am using version 4.1.3 as I want to be up to date. (The instructor is still using 3.3.7) I am following a Udemy tutorial.

In my angular.json, I have this: "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.less" ],

because at some point I would like the flexibility of .less.

robeverett avatar Oct 22 '18 18:10 robeverett

Downgrading to version 3 isn't a solution and is absurd. Imagine if as a professional developer you got told: "Oh our API won't work with .net core, so you'll have to re-write that app that you've just spent the last 6 months building to perfection in .net 4.5 !" :(

robeverett avatar Oct 22 '18 18:10 robeverett

The only way I can get to use the version 4 + styles is to use a CDN link at the top of app\src\styles.css:

@import 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css';

That's great when on occasions the bootstrapcdn server is down and all my users see an unstyled app - very professional.

Could someone PLEASE explain why 4 + can't be used the same as 3.3.7 upwards, WHAT is broke and WHY ?

robeverett avatar Oct 23 '18 07:10 robeverett

https://www.techiediaries.com/angular-bootstrap/

That link should clear up a lot of confusion.

robeverett avatar Oct 23 '18 08:10 robeverett

Thank You so Much @dotNetAthlete, So cut to the chase, The only thing we need to do is to use the latest Bootstrap: Add @import "~bootstrap/dist/css/bootstrap.css" to your styles.css in the src folder and you are good to go.

P.S : Still need to Install bootstrap first

:-)

navgag33 avatar Oct 28 '18 09:10 navgag33

I checked all the options and tried each suggested here in the post. But only working option is by uninstalling 4.* version by (npm uninstall bootstrap --save) and next by installing bootstrap 3.3.7 (npm install [email protected] --save)..

**

it worked like charm.

**

for other advanced members/users who dont want to disturb their existing version they have to deal with some intricacies of how to deal with such issues (for e.g. popper.js, jquery.js versions etc) and also know how to map these with the current bootstrap version.. then it might work!

but for me the priority to was to make my learning curve smooth and dont get mingled in these intricacies for now.

all the best!

happy coding.

vantive avatar Nov 15 '18 11:11 vantive

After installing the bootstrap dependency into your project just plug in the below code in your angular.json file.

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

Using, Angular CLI: 6.2.7 Node: 8.11.1 OS: win32 x64 Angular: 6.1.10

Hope this is helpful!

sanitreddy avatar Nov 16 '18 16:11 sanitreddy

Had thesame problem. Go to your angular.json And do this: "styles": [ "src/styles.scss", "node_modules/bootstrap/dist/css/bootstrap.min.css" ], 2- Close you server and launch it again: ng-serve.

ndibrithalea avatar Dec 17 '18 06:12 ndibrithalea

I had the same issue yesterday. I found a solution to it. I was importing the styles and script files in the wrong place in angular.json file It must be under build and not test object

I found the solution here https://stackoverflow.com/questions/51998505/styles-not-picking-from-angular-json-styles-array-angular-6-but-working-fine-wi

rahuls360 avatar Dec 25 '18 06:12 rahuls360

don't work until downgrade , best solution Uninstall angular -> install react -> enjoy

Houuse avatar Jan 07 '19 16:01 Houuse

Just put

"scripts": [ "./node_modules/bootstrap/dist/js/bootstrap.js" ],

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

Hope that it would work :)

arif7503 avatar May 14 '19 22:05 arif7503