In angular 2, I could just add them in the index.html like this:
<link rel="stylesheet" href="css/mycss.css">
But in angular 4 it has to be added to the angular-cli.json file in the styles and script array section.
In my situation they don't seem to be loaded at all. No error but when I view the app in the browser, I know the styles didn't load. When I add the styles and js to the index.html file too it doesn't get loaded, I get a 404 in the console.
How do I fix this? Below is my version of Angular cli: @angular/cli : 1.0.2 Node : 6.9.2
Adding external CSS in Angular Project.Go to your project folder > Click on src folder > Click on assets folder > Create a folder called css > and paste your css files here.
With the help of Angular CLI, you can install CSS or SCSS on your project and start working on that in a suitable way. If you are working with the CSS or SCSS in your angular project then it is very easy for you as compared to most other frameworks.
You can include css and js file in your angular project using npm command or direct insert link into src/index. html.
JavaScript can also be used to load a CSS file in the HTML document.
If you are using angular cli then go to your .angular-cli.json and then you can get "styles":[ ] as well "scripts":[ ] inside these you can add your css files and js files
"styles": [
yourfirst-css-file , //comma (,)is important
your-second-css-file
],
Eg:-
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"
],
and 404 error means that the file is not found.Try and append the complete "url" folder(src).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With