如何在Dropdown中绑定值

时间:2016-12-04 17:52:26

标签: angularjs

我试图在下拉年代试图绑定年份是从角度代码获取但是为什么它不在下拉列表中绑定

T

Angular.jS

 <div ng-controller="Supercntrl">
            <div>
  <select class="form-control" ng-model="YearList">
                    <option ng-repeat="Bin in BindYears" value="{{Bin.YearList}}">{{Bin.YearList}}</option>
                </select>
      </div>

2 个答案:

答案 0 :(得分:2)

您可以ng-repeat覆盖数组或对象,而不是不返回任何内容的函数(未定义)。

您的控制器需要准备一个可访问的数组

$scope.YearList = [];
for (var Y = 1991; Y <= 1995; Y++) {
    $scope.YearList.push(Y);
}

并且ng-repeat重复YearList

<select class="form-control">
    <option ng-repeat="Year in YearList" value="{{Year}}">{{Year}}</option>
</select>

答案 1 :(得分:2)

<select class="form-control">
    <option ng-repeat="Year in YearList" value="{{Year}}">{{Year}}</option>
     <option value=""> please Select Year </option>
</select>