0

I'm using angular-cli architecture for the initial setup of the app.

I want to import some of global css files into my index.html file. But as node_modules directory is outside of my src directory i'm not getting the accurate path and hence css is not applying.

I'm using path in following meaner,

I have tried without ../ also but it's also not working.

for ex.

<link href="node_modules/ng2-toastr/bundles/ng2-toastr.min.css" rel="stylesheet"/>

&&

<link href="../node_modules/ng2-toastr/bundles/ng2-toastr.min.css" rel="stylesheet"/>

But both the ways are not working.

Is anything wrong i'm doing?

Here is the app structure.

enter image description here

I'm using angular 2.2.1

Here is the error i'm getting

enter image description here

Thanks in advance

4
  • Have you checked your console? Are you getting a 404 error? Are you serving node_modules over your server? Commented Dec 5, 2016 at 14:33
  • Yes. I have updated question with screen Commented Dec 5, 2016 at 14:39
  • Maybe this answer will help you Commented Dec 5, 2016 at 14:44
  • I'm not having the angular-cli-build.js file. You can see in screenshort. Commented Dec 5, 2016 at 14:59

1 Answer 1

4

Check the documentation of angular CLI on how to install global libraraies,

you have to modify your angular-cli.json file to include css files in bundled style file not use directly in the HTML.

"styles": [
  "../node_modules/ng2-toastr/bundles/ng2-toastr.min.css"
]

Hope this helps!!

Sign up to request clarification or add additional context in comments.

12 Comments

Thanks Madhu Added the path in angular-cli.json but what should i write in index.html?
@PinankLakhani Nothing.
when you add it in styles folder, CLI bundles the file into styles.bundle so you don't have to add anything in your HTML, Cheers!!
still Not working. Its not applying the css "styles": [ "../node_modules/ng2-toastr/bundles/ng2-toastr.min.js" ],
you have to add css file not the JS file.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.