简体   繁体   English

如何在Angular中动态切换样式?

[英]How can I switch styles dynamically in Angular?

I have one styles.css and another styles-highcontrast.css , both of them essentially contain the same styles but the later adaptations for people with sight issues. 我有一个styles.css和另一个styles-highcontrast.css ,它们本质上都包含相同的样式,但后来针对有视力障碍的人进行了修改。
The styles-highcontrast.css is set to lazy in the angular.json. styles-highcontrast.css highcontrast.css在angular.json中设置为lazy

How can I switch between the two with just a click of a button? 只需单击一个按钮,如何在两者之间切换?

Thanks 谢谢

Have your high-contrast css wrapped in some specific class, eg: 将高对比度的css包装在某些特定的类中,例如:

a {color: red;}

.high-contrast a {color: extraRed;}

And in HTML: 在HTML中:

<body ng-class="{'high-contrast': vm.useHighContrast}">
    <button ng-click="vm.useHighContrast = !vm.useHighContrast">Switch contrast</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM