css - 使用 ngStyle 传递 CSS 值

标签 css angular

我有一个发送值的服务,我需要将该值传递给 CSS 文件,以便我可以控制仪表的移动量。 该值介于 0 和 0.5 之间,并改变

transform:rotate( {NUMBER} turn)

在使用先前的 nGclass 动态选择的类上。

示例:如果我的 var 是 0.5,我需要生成的 CSS 代码是

transform:rotate(.5turn)

我该如何管理?

我试过了

[ngStyle]="{'transform:rotate(.5turn)': dashService.variable}"

和相同想法的其他变体,但它似乎不起作用。

最佳答案

您可以使用插值语法:

[ngStyle]="{ 'transform': 'rotate(' + dashService.variable + 'turn)': }"

关于css - 使用 ngStyle 传递 CSS 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58118295/

相关文章:

javascript - 我尝试使用 Bootstrap 模式类制作弹出式注册表单,但弹出式窗口不起作用

html - 带有滚动和自动大小列的表格

css - 确保 div 永远不会相互交叉

angular - 如何在 angular cli 项目中包含来自 node_modules 的 Assets

angular - 使用URL访问时出现 Angular 错误500

html - 分区类 :hover + divclass2 - not working

css - 如何让条件 css 在 Blogger/Blogspot 上工作?

javascript - 使用 Azure 应用服务部署的 Angular 应用程序无法找到使用 ngserve 时找到的 Assets

Angular 路由解析器或 onInit?

angular - 在子空路径或父路径中指定组件