Angular空选项删除

时间:2015-06-27 14:59:44

标签: javascript angularjs angularjs-directive angularjs-ng-repeat angular-ngmodel

当我重复数组时,我的空选项有问题。 这是代码。

查看:

<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 个答案:

答案 0 :(得分:1)

尝试使用ngOptions代替ngRepeat

试试这个

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