admin管理员组文章数量:1308191
I am developing an Angular v19 application and I am struggling to find a way to programatically change the material theme color palettes.
The reason for this feature is to make it very apparent when testing the application that we are not accidently using the production version. I am trying to read the current environment (production, development, testing) and set the color paette accordingly.
I first tried creating separate scss files for each scenario and hoped to use fileReplacements
in angular.json
to set a style file from which I could read a colour palette. It appears that fileReplacements
doesn't allow .scss
files.
I then tried using a SASS @if
in the main styles.scss
file to set the mat.theme
conditionally on a css variable which could be changed programatically, but I can't seem to figure this out.
Reading the docs there may be a way to achieve this with $overrides
.
If anyone knows how to switch themes, or color palettes programatically I would be very interested to learn.
I am developing an Angular v19 application and I am struggling to find a way to programatically change the material theme color palettes.
The reason for this feature is to make it very apparent when testing the application that we are not accidently using the production version. I am trying to read the current environment (production, development, testing) and set the color paette accordingly.
I first tried creating separate scss files for each scenario and hoped to use fileReplacements
in angular.json
to set a style file from which I could read a colour palette. It appears that fileReplacements
doesn't allow .scss
files.
I then tried using a SASS @if
in the main styles.scss
file to set the mat.theme
conditionally on a css variable which could be changed programatically, but I can't seem to figure this out.
Reading the docs there may be a way to achieve this with $overrides
.
If anyone knows how to switch themes, or color palettes programatically I would be very interested to learn.
Share Improve this question asked Feb 2 at 19:15 ChrisChris 1532 silver badges12 bronze badges1 Answer
Reset to default 1Production has its own styles
array in angular.json
, just add the style here and you can configure styles as per the environment:
"configurations": {
"production": {
"styles": ["/src/light.scss"],
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
本文标签: Angular v19 Conditional Material Theme PalettesStack Overflow
版权声明:本文标题:Angular v19 Conditional Material Theme Palettes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741837255a2400291.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论