如何在 *ngFor 中设置动态 id? [英] How to set dynamic id in *ngFor?
本文介绍了如何在 *ngFor 中设置动态 id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Angular 2中设置动态id
?
我试过了:
但它不起作用.
解决方案 <罢工>对于 id
属性,这可能也有效(我自己还没有尝试过)
How to set dynamic id
in Angular 2?
I have tried:
<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" }
];
but it does not work.
解决方案 <div class = "CirclePoint" *ngFor="let c of circles"
[attr.id]="'Location' + c.id">
</div>
<div class = "CirclePoint" *ngFor="let c of circles"
attr.id="Location{{c.id}}">
</div>
For the id
attribute this might work as well (not tried myself yet)
<div class = "CirclePoint" *ngFor="let c of circles"
[id]="'Location' + c.id">
</div>
这篇关于如何在 *ngFor 中设置动态 id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆