BalajiK
BalajiK

Reputation: 2701

angular 2 select ngModelChange

This question is from Accessibility perspective. I have a select statement as below and use Angular 2. It works perfectly as it is supposed to while using the mouse. When using the keyboard down arrow key I need to be able to select an option and press enter key so that action takes place. How do I achieve that in select statement.

<select [(ngModel)]="selItem" class="form-control" name="itemSelection" (ngModelChange)="onItemChange($event)"

Also not interested in having a separate submit button to action upon the item that was selected from the select dropdown

Upvotes: 3

Views: 4269

Answers (1)

Sandip Jaiswar
Sandip Jaiswar

Reputation: 93

Try this:

    <select [(ngModel)]="selItem" class="form-control" name="itemSelection" (ngModelChange)="onItemChange($event)">
        <option [value]="x" *ngFor="let x of names">{{x}}</option>
    </select>

 names = ['ram','sham','vijay']
  selItem = 'ram';
  onItemChange(data) {
    console.log(data);
    this.selItem = data;
  }`enter code here`

Upvotes: 2

Related Questions