반응형
* ngFor에서 동적 ID를 설정하는 방법은 무엇입니까?
id
Angular 2에서 동적을 설정하는 방법은 무엇입니까?
나는 시도했다 :
<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
속성이 힘의 작품뿐만 아니라 (아직 자신을 시도하지)
<div class = "CirclePoint" *ngFor="let c of circles"
[id]="'Location' + c.id">
</div>
이 시도:
<div class = "CirclePoint" *ngFor="let c of circles">
<div id="location_{{c.id}}">write something which you want like c.x </div>
</div>`
바라건대 이것은 당신을 위해 일할 것입니다. StackOverflow를 검색 한 결과이 답변을 찾았습니다 .
일반적인 id="#c"
사용 대신 구성 요소 태그 내부 [id]="#c"
. 이것은 동적 클래스 이름에도 적용됩니다. 아래 예를 참조하십시오.
<div class = "CirlePoit" *ngFor="#c of circles" [id] = "#c"> </div>
이것은 또한 작동합니다.
<div class = "CirclePoint" *ngFor="let c of circles">
<div [id]="c.id"></div>
</div>
접두사를 추가하려면 "loc"이라고 말하십시오.
<div class = "CirclePoint" *ngFor="let c of circles">
<div [id]="'loc' + c.id"></div>
</div>
[]를 사용하면 값을 동적으로 추가하는 데 도움이됩니다.
참조 URL : https://stackoverflow.com/questions/34568497/how-to-set-dynamic-id-in-ngfor
반응형
'program tip' 카테고리의 다른 글
Docker 명령 줄의 Docker 레지스트리에서 특정 태그가있는 Docker 이미지를 찾으려면 어떻게해야합니까? (0) | 2020.12.31 |
---|---|
Bluebird로 Node의 child_process.exec 및 child_process.execFile 함수를 약속하는 방법은 무엇입니까? (0) | 2020.12.30 |
내 onItemSelectedListener가 ListView에서 호출되지 않는 이유는 무엇입니까? (0) | 2020.12.30 |
WebBrowser 전체 페이지 로딩 감지 (0) | 2020.12.30 |
Sun / Oracle JVM의 기본 XSS 값은 어디에서 찾을 수 있습니까? (0) | 2020.12.30 |