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:

  1. <select (change)="readdata($event.target.dataset)>...<select>
  2. <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> 

plunker example


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -