12

I need to filter items in ng-repeat so that only the items which not appear in alreadyAddedValues() array will be shown:

<ul class="dropdown-menu">
    <li ng-repeat="v in values() | filter: { ????? } ">{{value.name}}</li>
</ul>

$scope.values() = function(){
    ................
}

$scope.alreadyAddedValues() = function()
{
    //returns an array
}

The search of an already added value should perform by value.shortName

Paul
  • 25,812
  • 38
  • 124
  • 247

1 Answers1

31

You can, for example, use a custom function to do the filtering:

<li ng-repeat="v in values() | filter:filterAlreadyAdded ">{{value.name}}</li>

On the controller:

$scope.filterAlreadyAdded = function(item) {
    // filter logic here...
    // return false if item already added, true otherwise
};

jsfiddle: http://jsfiddle.net/bmleite/5VbCJ/

bmleite
  • 26,850
  • 4
  • 71
  • 46
  • 3
    I made an alternate fiddle to pass pass the array of already added values to make it a bit more generic. Located here http://jsfiddle.net/4MBbw/ – ug_ Nov 06 '13 at 07:53