Ahmed Ahmed - 6 months ago 22
AngularJS Question

How to hide options in select list Angular JS?

I have

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>


And
$scope.limit = 1991;


I try to hide options by condition:

ng-hide="year.id < limit"


It does not work

Answer

Try like this by using filter:show

ng-repeat="year in data.dateList.year | filter:show"

JS

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

if you want to get index

Try like this

$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;
}