设置下拉列表控件的选定选项不起作用

时间:2014-07-10 20:03:34

标签: angularjs

我有以下HTML标记:

<select id="selectDays" class="form-control" ng-model="selectedDays"
        ng-options="value.id as value.name for value in searchDays" ng-change="selectChange()">
</select>

searchDays是$ scope中定义的json数组:

    $scope.searchDays = [{ name: "30 Days", id: 30 }, { name: "60 Days", id: 60 }, { name: "90 Days", id: 90 }];

我希望选择第三个选项,即90天,我正在使用此代码,但它不起作用:

    //select 90 Days
    $scope.selectedDays = $scope.searchDays[2];
我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

指定id属性:

$scope.selectedDays = $scope.searchDays[2].id