如何在ionic2 / angular2中设置动态id(* ngFor)? [英] How to set dynamic id(*ngFor) in ionic2/angular2?

查看:331
本文介绍了如何在ionic2 / angular2中设置动态id(* ngFor)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在angular2中设置动态ID?

How to set dynamic id in angular2?

我试过了

<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"  }
];

但它不起作用。

推荐答案

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


对于 id 属性这也可能有用(我还没试过)

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>

这篇关于如何在ionic2 / angular2中设置动态id(* ngFor)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆