2017-02-28 51 views
0

我有一个设置组件值的ComboBox的问题。组合框的值在levelCombined [j] [i] ['result']中加载angular 2以编程方式设置组合框的值

   <tr *ngFor="let x of levelCombined, let j=index"> 
       <td *ngFor="let y of x, let i=index"> 
        <select class="form-control" id="comboBoxLevelSelction" 
          name="levelSelection" 
          (change)="onLevelSelect($event,j,i)"> 
         <option disabled selected value> - select an option -</option> 
         <option *ngFor="let ln of levelNames" [ngValue]="levelCombined[j][i]['result']">{{levelCombined[j][i]['result']}}</option> 
        </select> 
       </td> 
      </tr> 

当前所有组合框都设置为默认选项。我认为我没有正确使用ngValue。

+0

您可以使用属性绑定语法'[value] =“您的值”'。有关绑定不同表单控件的更多细节可以在这里找到。 [https://scotch.io/tutorials/how-to-deal-with-different-form-controls-in-angular-2](https://scotch.io/tutorials/how-to-deal-with- different-form-controls-in-angular-2) – HirenParekh

回答

1

使用[(ngModel)]将默认选项与组件的值绑定。

+0

你是对的我使用'code'。 <选择选项[ngModel]] =“levelCombined [j] [i]”ngDefaultControl> {{levelCombined [j] [i] ['level']}}'code'。它的工作原理。谢谢! – playerone

相关问题