Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular.js: filter ng-repeat by absence in array

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

like image 899
Paul Avatar asked Feb 12 '13 19:02

Paul


1 Answers

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/

like image 166
bmleite Avatar answered Nov 06 '22 10:11

bmleite