Angularjs dropdown select value

时间:2016-10-20 12:59:36

标签: javascript angularjs angularjs-scope

I have this dropdown

<select class="form-control" ng-model="LoanDetailsVM.PaymentPeriodMonths">
           <option value="1">Monthly</option>
           <option value="3">Quarterly</option>
 </select>

The LoanDetailsVM.PaymentPeriodMonths can be either 1 or 3, but the proper option is not selected when I'm opening the page.

Is there anything else I need to add in order for the correct option to be selected?

1 个答案:

答案 0 :(得分:1)

You should use [(ngModel)] instead of ng-model and [ngValue] instead of value:

<select class="form-control" [(ngModel)]="LoanDetailsVM.PaymentPeriodMonths">
       <option [ngValue]="1">Monthly</option>
       <option [ngValue]="3">Quarterly</option>
</select>