Angular2svg:circle填充属性绑定

Angular 2 svg:circle fill attribute binding

我正在尝试将 <svg:circle> 元素中的 fill 属性的值绑定到组件中的 color: string = "#cecece" 变量。后来看了很多文章,也尝试过各种方法,但是都没有成功:

style="fill: {{color}}"

[style]="fill: color"

[style]="fill: 'color'"

[attr.style]="fill: color"

[attr.fill]="color"

[attr.style.fill]="color"

fill="{{color}}"

有什么方法可以实现吗?我什至在考虑我在其他地方遇到问题的可能性。

在没有 angular 绑定的情况下,它通常的工作方式是: <circle fill="#cecece"></circle>

[attr.fill]="color"  

attr.fill="{{color}}"

应该适合你