Angular 2 svg:circle fill attribute binding

padr picture padr · Aug 10, 2017 · Viewed 10.3k times · Source

I am trying to bind the value of the fill attribute in an <svg:circle> element to my color: string = "#cecece" variable in my component. I have read many articles and tried different ways afterwards, however, noone was successful:

style="fill: {{color}}"

[style]="fill: color"

[style]="fill: 'color'"

[attr.style]="fill: color"

[attr.fill]="color"

[attr.style.fill]="color"

fill="{{color}}"

Is there some way of making this work? I am even thinking about the possibility that I have a problem somewhere else.

The way it usually works without angular binding is: <circle fill="#cecece"></circle>

Answer

yurzui picture yurzui · Aug 10, 2017
[attr.fill]="color"  

or

attr.fill="{{color}}"

should work for you