简体   繁体   English

Angular 2动态全局CSS

[英]Angular 2 dynamic global css

I'm working on an app where each user can define custom colors for its dashboard. 我正在开发一个应用程序,每个用户都可以为其仪表板定义自定义颜色。 Like textColor, accentColor and backgroundColor; 像textColor,accentColor和backgroundColor一样;

The entire UI will use those colors. 整个用户界面将使用这些颜色。

I know how to set a css property dynamic but doesn't seem correct to do it every single element. 我知道如何动态设置css属性,但似乎每个元素都不正确。

I was wondering if I can create a dynamic css and inject it into the app. 我想知道是否可以创建动态CSS并将其注入到应用程序中。 (is it too much workaround?) (是否有太多解决方法?)

I managed to make it work by using a server-side generated theme.css (something like /users/1.css ). 我设法通过使用服务器端生成的theme.css(类似于/users/1.css )使其工作。 Can you smell it? 你能闻到吗?

What's the proper way to do it? 正确的做法是什么?

We've developed an application that had to be white label, so we've created directives for the editable items and the directives listened to the service that handled the layout package from server, overwriting if needed the property. 我们开发了一个必须为白色标签的应用程序,因此我们为可编辑项目创建了指令,并且该指令侦听了处理来自服务器的布局包的服务,并在需要时覆盖了该属性。 In your case you could choose to have only textColor, accentColor and backgroundColor directives instead of each layout component have your own layout directive. 在您的情况下,您可以选择仅具有textColor,accentColor和backgroundColor指令,而不是每个布局组件都具有自己的布局指令。

I'm currently looking for a way to actually receive an entire scss from server that would overwrite the variables inside Sass, but I could not find any approach yet. 我当前正在寻找一种从服务器实际接收整个scss的方法,该方法将覆盖Sass中的变量,但是我找不到任何方法。

I would also share this article, that could be helpful: https://engineering.thetrainline.com/how-we-implemented-a-single-page-application-using-react-3f22e4d545c4 我还将分享这篇文章,这可能会有所帮助: https : //engineering.thetrainline.com/how-we-implemented-a-single-page-application-using-react-3f22e4d545c4

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

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