Angular2 *ngFor with SVG circle

烈酒焚心 提交于 2019-12-22 10:35:53

问题


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"

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.

Does anyone know how I can fix this error?


回答1:


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>


来源:https://stackoverflow.com/questions/45571792/angular2-ngfor-with-svg-circle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!