angular - Angular2 - How to access value stored in data attributes -
this may have been asked, i've tried googling sometime without having getting solution.
i have following select field in angular2, how access stored value in data attribute of attr.data-thisdata
?
<select #dial"> <option *ngfor="let of somethings" [value]="something.value" [attr.data-thisdata]="something.data" >{{something.text}}</option> </select>
i have tried following not getting values:
<select (change)="readdata($event.target.dataset)>...<select>
<select (change)="readdata($event.target.dataset.thisdata)>...<select>
my readdata simply:
readdata(data:any){ console.log(data) }
edit 1: added plunker ease of reference
edit 2: included plunker günter's answer
with [ngvalue]
instead of value can assign object instead of string.
<select #dial" ngmodel (ngmodelchange)="$event.data"> <option *ngfor="let of somethings" [ngvalue]="something" [attr.data-thisdata]="something.data" >{{something.text}}</option> </select>
Comments
Post a Comment