Angular 2: How to get the selected value from different options of a form?

There is a way to get the value from different options. check this plunker

component.html

 <select class="form-control" #t (change)="callType(t.value)">
      <option *ngFor="#type of types" [value]="type">{{type}}</option>
    </select>

component.ts

this.types = [ 'type1', 'type2', 'type3' ];
   this.order = {
      type: 'type1'          
  };  

  callType(value){
    console.log(value);
    this.order.type=value;
  }

Been tackling this problem for a few hours.

Checked in the (incomplete) documentation to find an item in the NgSelectOption page called "ngValue"

Not sure if this is the intended use but it seemed to work fine.

So instead of using

[value]="item"

Use:

[ngValue]="item"

Just use ngModel on the select and ngModelChange event if you want to do something when it changes.


In fact I can't reproduce your problem. I created a plunkr with a very simple form with an input and a select. When I submit the form, I have actual values in the bound object. See this plunkr: https://plnkr.co/edit/5C3agW7QZfcrdt88QzSh?p=preview.

Feel free to tell me if I didn't correctly understand your problem.

Thierry