0

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

1
  • 1
    you can not hide <option> cross browser. IE for example does not support it Commented Sep 18, 2015 at 14:18

1 Answer 1

5

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;
}
Sign up to request clarification or add additional context in comments.

8 Comments

you don't need to. it'll send instance of data.dateList.year into show from filter
I need something like as: filter:show:$index" AJ: $scope.show=function(year, index){..} Is it correct?
why need index where your have year object ?? you can find index using object from their list.
I have model in ng-repeat with $index like as modal[$index] And I need curret $index to function show() that to compare two models with $index current
@Ahmed try this: filter:show($index) and $scope.show = function (index) { return function (year) { .. }; };
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.