[英]Angular's main html file can't use the styles.scss file inside the src/styles folder
I'm new to Angular.我是 Angular 的新手。
In order to use the 7-1 scss pattern in my project, I created a styles folder inside the src folder "src/styles", and linked the components to the src/styles/style.scss and it works fine.为了在我的项目中使用 7-1 scss 模式,我在 src 文件夹“src/styles”内创建了一个 styles 文件夹,并将组件链接到 src/styles/style.scss,它工作正常。
The problem I'm having now is that the html and body elements within the main index.html file aren't affected by these styles.我现在遇到的问题是主 index.html 文件中的 html 和正文元素不受这些 styles 的影响。
Here's a look at my directory structure下面看一下我的目录结构
I tried importing the styles needed inside the src/styles.scss file and it worked but I don't want to repeat my code.我尝试在 src/styles.scss 文件中导入所需的 styles 并且它有效,但我不想重复我的代码。
Wanted behavior :通缉行为:
The main index.html can use the scss styles inside the "src/styles/styles.scss" I created with no problem.
Actual behavior :实际行为:
The main index.html can only access the default style.scss folder by default
How can I fix this so that the elements inside the index.html can use the styles from within my styles folder without having to repeat my work twice?我该如何解决这个问题,以便 index.html 中的元素可以在我的 styles 文件夹中使用 styles 而不必重复我的工作?
Edit: the problem occurs despite the already made changes to the angular.json file as you can see here编辑:尽管已经对 angular.json 文件进行了更改,但问题仍然存在,如您在此处看到的
Thank you in advance先感谢您
you need to add your src/styles/styles.css
inside angular.json您需要在 angular.json 中添加您的
src/styles/styles.css
8CBA22E28EB17B5F5C6AE2A266AZ
there is style object有款式 object
{
"projects":{
"yourProjectName": {
"architect":{
"build:{
"options":{
"assets":[...],
"styles": [
"src/styles/styles.scss",
]
//..rest of config
}
}
}
}
}
Note: After adding please restart your local development server or if in production re-deploy, to see changes注意:添加后请重新启动本地开发服务器,或者如果在生产中重新部署,以查看更改
Solved.解决了。 I was able to solve the problem by importing all the sass files from the src/styles into the main styles.scss file.
我能够通过将所有 sass 文件从 src/styles导入主styles.scss文件来解决该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.