我是Angular 2的新手。 以下是div列表:
<div class="list">
<div value="A">A</div>
<div value="B">B</div>
<div value="C">C</div>
<div value="D">D</div>
<div value="E">E</div>
</div>
如何从中选择一个div(如收音机列表),然后处理所选值?
答案 0 :(得分:2)
试试这个
<div class="list">
<div value="A" [class.highlight]="selection=='A'" (click)="clickFunction('A')">A</div>
<div value="B" [class.highlight]="selection=='B'" (click)="clickFunction('B')">B</div>
<div value="C" [class.highlight]="selection=='C'" (click)="clickFunction('C')">C</div>
<div value="D" [class.highlight]="selection=='D'" (click)="clickFunction('D')">D</div>
<div value="E" [class.highlight]="selection=='E'" (click)="clickFunction('E')">E</div>
</div>
selection = "A";
clickFunction(value){
console.log(value)
this.selection = value;
}