Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 svg:circle fill attribute binding

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>

like image 347
padr Avatar asked Aug 10 '17 09:08

padr


People also ask

How do I use SVG in angular?

Get Data from a Server You can use SVG files as templates in your Angular applications. When you use an SVG as the template, you are able to use directives and bindings just like with HTML templates. Use these features to dynamically generate interactive graphics.

How do you bind attributes in angular?

Then, you set the attribute value with an expression that resolves to a string. When the expression resolves to null or undefined, Angular removes the attribute altogether. One of the primary use cases for attribute binding is to set ARIA attributes. Another common use case for attribute binding is with the colspan attribute in tables.

How do I set the circumference of a circle in SVG?

Out SVG consists of two circles. One circle will be the outer grey while the other will be the progress value that will be updated by Angular. If we look at our SVG, the first thing we do is bind the circumference value to each circle. The circumference value will be set in the component class.

How to bind two-way data in angular?

You can see that the former is property binding where as the latter is event binding and the combination of both results in two-way binding in Angular. Syntax for two-way data binding in Angular is [ ()]. The [ ()] syntax combines the brackets of property binding, [], with the parentheses of event binding, ().


1 Answers

[attr.fill]="color"  

or

attr.fill="{{color}}"

should work for you

like image 118
yurzui Avatar answered Oct 23 '22 14:10

yurzui