changing css style dynamically from component in Angular 5

5.9k Views Asked by At

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

There are 1 best solutions below

0
Rachit Shroff On BEST ANSWER

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.