我想在我的angular 5组件模板中使用可变宽度,如下所示:
<style>
input:checked + .slider:before {
transform: translateX({{width}}px);
}
</style>
而“宽度”是在组件中定义的变量!
但是“ {{width}}”没有解析,如何实现此功能。谢谢!
最佳答案
在这种情况下,您可以使用Angular ngStyle:
[ngStyle]="{ width: width }"
看看这个demo
关于css - 在angular中,如何在样式中使用组件变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48295339/