如何隐藏选择列表Angular JS中的选项?

时间:2015-09-18 14:10:09

标签: angularjs

我有ng-repeat

<option ng-repeat="year in data.dateList.year" ng-hide="year.id < limit" value="{{year.id}}" ng-selected="year.id == 0">
   {{year.value}}
</option>

$scope.limit = 1991;

我尝试按条件隐藏选项:

ng-hide="year.id < limit"

不起作用

1 个答案:

答案 0 :(得分:5)

使用filter:show

尝试这样做
ng-repeat="year in data.dateList.year | filter:show"

JS

$scope.show=function(year){
  return year.id > $scope.limit
}

如果你想得到索引

试试这个

$scope.show = function(year) {
    console.log(getIndex($scope.data.dateList.year, year))
    return year.id > $scope.limit
}

function getIndex(dataList, data) {
    var index = -1;
    dataList.some(function(item, i) {
        if (JSON.stringify(item) == JSON.stringify(data)) {
            index = i;
            return true;
        }
    });
    return index;
}