2016-12-04 77 views
0

在這裏,我想結合在十年下拉年從角碼讀取,但爲什麼它不綁定在下拉列表如何綁定在下拉值

<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> 

Angular.jS

angular.module('MyApp',[]) 

.controller('Supercntrl',function($scope){ 
    BindYears(); 

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

回答

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

您可以在數組或對象上使用ng-repeat,而不是不返回任何內容的函數(未定義)。

你的控制器需要準備一個可訪問陣列

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

和NG-重複越過那YearList

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

我怎樣才能顯示,請選擇年份 –