Ahmed
Ahmed

Reputation: 255

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

Upvotes: 0

Views: 2862

Answers (1)

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

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

Upvotes: 5

Related Questions