如何从div列表中选择 - Angular 2?

时间:2017-06-29 06:02:05

标签: angular ionic-framework ionic2

我是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(如收音机列表),然后处理所选值?

1 个答案:

答案 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;

}