-1

I was adding external global styles to a project and did not add them in "angular.json". As far as I have seen or read on various articles, most people do include their styles within "angular.json". But I got the styles working just fine even after omitting that step. Although one reason that I can figure out is that the main styles file "src/styles.css" is already there and I imported all my styles there. So that could be the reason it's working. Besides, I also had to add the styles and scripts in "index.html" to make it work. Just curious about the reasons.

Thanks!!

bruTeFoRcE
  • 37
  • 6

2 Answers2

1

When you add styles to angular-cli json then angular compiles all the styles into javascript file and all those styles will be added to head tag. The behavior is same when you follow Angular's component Styling mechanism when the components get loaded into the DOM. So I would not recommend you to add in angular json instead you can add in index.html

I would recommend this article to you

https://stackoverflow.com/questions/37484937/angular-cli-how-to-add-global-styles/42840828#:~:text=In%20an%20Angular%20project%2C%20when,This%20angular

0

Well, after experimenting a bunch, I found out that scripts have to be referenced in the "angular.json" file. It's a bit weird behavior otherwise. So, the following steps will fix most errors regarding scripts,

  1. Add them into script tag in index.html

  2. Import them in both scripts fields in angular.json

Thanks!

bruTeFoRcE
  • 37
  • 6