How to dynamically change css values (like color in whole app) etc

后端 未结 4 1977
孤独总比滥情好
孤独总比滥情好 2021-02-12 15:39

I have one question...

If you want conditional styling: you must use ng-class or ng-style construction.

But...

For example: I\'

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-12 16:15

    You could write the CSS rule in JavaScript and add it to a stylesheet dynamically. A couple of good articles on how to do that are here and here.

    var myColor = '#FF00FF';
    var stylesheet = /* get stylesheet element */;
    stylesheet.insertRule('.dynamic-color { background-color:"' + myColor +'";}',0);
    

    Of course, in a pure Angular way, you would create a directive that wraps the DOM/stylesheet interaction.

提交回复
热议问题