gpt4 book ai didi

angular - 如何在 *ngFor 中设置动态 id?

转载 作者:太空狗 更新时间:2023-10-29 16:46:24 24 4
gpt4 key购买 nike

如何在 Angular 2 中设置动态 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" }
];

但它不起作用。

最佳答案

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

关于angular - 如何在 *ngFor 中设置动态 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34568497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com