简体   繁体   English

Angular2 * ngFor with SVG circle

[英]Angular2 *ngFor with SVG circle

I am trying to create a legend/key for a pie chart with a small circle with the same color in the graph and text next to it. 我正在尝试为饼图创建一个图例/关键字,其中一个小圆圈在图形和旁边的文本中具有相同的颜色。 However, this is the error that I am getting when I try to do this: 但是,当我尝试这样做时,这是我得到的错误:

"Template parse errors: Can't bind to 'fill' since it isn't a known native property" “模板解析错误:无法绑定到'fill',因为它不是已知的本机属性”

Below is my code: 以下是我的代码:

<svg *ngFor="let item of items;" width="250" height="75">
    <circle cx="50" cy="50" r="20" fill={{item.color}} />
    <text x="100" y="50">{{item.name}}</text>
</svg>

item.color and item.name are both strings, and when I try to just display them both as text, all the values do appear. item.color和item.name都是字符串,当我尝试将它们都显示为文本时,所有值都会出现。

Does anyone know how I can fix this error? 有谁知道如何解决这个错误?

Try the following, 试试以下,

<svg *ngFor="let item of items;" width="250" height="75">
    <circle cx="50" cy="50" r="20" [attr.fill]="item.color" />
    <text x="100" y="50">{{item.name}}</text>
</svg>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM