如何在angular2中设置动态ID?
我试过了
<div class = "CirclePoint" *ngFor="#c of circles" id = "{{ 'Location' + c.id }}"></div>
this.circles = [
{ x: 50 , y: 50 ,id : "oyut1" },
{ x: 100 , y: 100 ,id : "oyut3" },
{ x: 150 , y: 150 ,id : "oyut2" }
];
但它不起作用 .
3 回答
对于id属性,这可能也有效(我还没试过)
<div class =“CirclePoint”* ngFor =“let c of circles” [id] =“'位置'c.id”> </ DIV>
试试这个:
希望这对你有用 . 我搜索了StackOverflow,我发现了这个answer .
在组件标签内部而不是通常的
id="#c"
使用[id]="#c"
. 这也适用于动态类名 . 见下面的例子: