Pianistprogrammer
Pianistprogrammer

Reputation: 637

How can i remove the item already selected from the dropdown list

I have created a plunker for this code, when I add an item row and select from the list of items, I don't wannt that item to be in the list again when i add another row of items to select from. Check the plunker i created, I really don't know how to go about it https://plnkr.co/edit/u5cSwJqCwL5clpcWGuhN

$scope.items = [];
    $scope.filter = {};
    $scope.addItem = function () {
        if ($scope.items === null) {
            $scope.items = [{}];
            return;
            }
        $scope.items.push({});
        };
    $scope.removeItem = function (index) {
    $scope.items.splice(index, 1);
        calculateTotal();

    };

Upvotes: 0

Views: 193

Answers (1)

You need to use filter based on function like this:

ng-options="item.id as item.name for item in laundryitems|filter: myfilter(item)"

and:

$scope.usedItemsArray=[];
$scope.myfilter=function(value){
    return function(){
    return ($scope.usedItemsArray.indexOf(value)<0);//not found
    }
};

finally you need to add selected items to usedItemsArray and remove them when unselected.

Upvotes: 2

Related Questions