2017-08-08 84 views
2

我想创建一个饼图的图例和关键字,并在它旁边的图形和文本中使用相同颜色的小圆圈。然而,这是当我尝试这样做,我得到的错误:Angular2 * ngFor与SVG圈

“模板解析错误: 不能绑定到‘补’,因为它不是一个已知的原生属性”

以下是我的代码:

<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和item.name都是字符串,当我试图只显示它们作为文本时,所有的值都会出现。

有谁知道我该如何解决这个错误?

+1

尝试'补= “{{item.color}}”' –

+0

或'所有[填补] = “item.color”' – peinearydevelopment

+0

谢谢!我可以用[attr.fill] =“item.color” – Alan

回答

1

尝试以下,

<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>