changing css style dynamically from component in Angular 5

…衆ロ難τιáo~ 提交于 2020-01-23 17:03:51

问题


I am using materialized range:

<div class="range-field  col s6">
  <input type="range" id="test5" min="0" max="100"  #ranger (input)="yourMethod(ranger.value)"/>
</div>

This input creates in HTML span tag with class thumb, how could I change the color dynamically by changing the range? Is it possible to define in css .thumb {background-color: somevariable}, and change it from the component?


回答1:


You can dynamically set the color in html through a variable defined in the component.

<p [style.color]="variable"></p>

define the value of variable in component. But make sure you have a default value defined otherwise it will throw an error.



来源:https://stackoverflow.com/questions/50698285/changing-css-style-dynamically-from-component-in-angular-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!