1

我有空選項的問題,當我通過數組重複。 這裏是代碼。角空選項刪除

查看:

<select ng-model="getseason" class="form-control"> 
    <option ng-repeat="season in seasons" value="{{ season }}"> 
     Season {{ season + '/' + seasonaddone(season) }} 
    </option> 
</select> 

型號:

$scope.getseason={}; 

$scope.seasons = [2014,2013,2012,2011,2010,2009,2008,2007,2006,2005]; 

$scope.getseason = $scope.seasons[0]; 

$scope.seasonaddone = function(season){ 
    return ++season; 
} 

$scope.$watch('getseason',function(){ 
    console.log($scope.getseason); 
    console.log(typeof $scope.getseason); 
}); 

如何刪除空的選項? 我發現很多類似的問題,但我找不到解決方案。

回答

1

嘗試使用ngOptions代替ngRepeat

嘗試這樣

<select ng-model="getseason" class="form-control" ng-options="season as 'Season '+ season + '/' + seasonaddone(season) for season in seasons"> 
</select> 
+0

TNX,爲答。它的工作,但不完全如何我想要如何改變選項標籤之間的文本?價值是好的。 – user3590094

+0

'季節季節'甲酸鹽是作爲價值財產的'價值作爲文本'左側,而原樣的權利是文本財產。 –

+0

那麼,以這種方式不可能在生成的選項標籤中添加額外的文本? – user3590094