Set sass variable value in Angular 7

后端 未结 6 2660
悲哀的现实
悲哀的现实 2021-02-19 22:11

I have been working with angular for the last few weeks, and now I have a requirement to dynamically style a public site. The site admin set various color codes as well as a log

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 22:41

    While @Cold Cerberus has suggested a good approach and is right about maintaining style related things at front-end, i am suggesting some ways for this.

    As you said you want various colour combination,you can use Conditional CSS of SASS.

    body[theme="theme1"] {
       // theme 1 css
    }
    
    body[them="theme2"] {
        // theme 2 css
    }
    

    You can use sass theme map along with conditional css.

    Just update your attribute and theme will be applied automatically.

        themeChange() {
        const dom = document.querySelector('body');
        dom.theme = theme1;    // change theme here
        }
    

    If you are very particular about some element style which should be updated from back-end (like colour code) you can use ng-style along with theme approach.

    ...
    

    You have to use smart combination of above in order to fulfill your requirement.

提交回复
热议问题