Angular 4 On select change get attribute data value
As your attr.data-some-data
value is the same as value
you can simply write:
console.log(event.target.value);
But if you really want to get that data-attribute then use the following code:
const selectEl = event.target;
const val = selectEl.options[selectEl.selectedIndex].getAttribute('data-somedata');
// or
const val = selectEl.options[selectEl.selectedIndex].dataset.somedata;
Try like this :
use (ngModelChange) instead of (change)
<select class="form-control input-sm" [(ngModel)]="o.id" formControlName="optionals" (ngModelChange)="menuChange($event)">
<option *ngFor="let menu_optional of menu_optionals" [value]=" menu_optional.id" [attr.data-somedata]="menu_optional.id">{{ menu_optional.name }}</option>
</select>