8

I have a drop down filter and it is working fine. See the link
http://plnkr.co/edit/c5Hrqfv1eA5qfQpkYR41?p=preview
But I want to add one more value in to the drop down, then it is not working correctly. I have tried with the below code.

<select ng-model="filterDeck.deckDetail" ng-options="deck.name as (deck.name+' - '+deck.level) for deck in data">
</select>

Please help me to do this. Thank you.
Vimal

2 Answers 2

18

If you don't want to make any changes to the filter use this select:

<select ng-model="filterDeck.deckDetail" ng-options="deck as deck.name + ' - '  + deck.level for deck in data">

The above option will bind the entire object to the model.

If you just want to bind the id to the model you need to update your select and filter to the following :

<select ng-model="filterDeck.deckDetail" ng-options="deck.id as deck.name + ' - '  + deck.level for deck in data">

Then update your filter to this:

$scope.customDeck = function (data) {
    if (data.id === $scope.filterDeck.deckDetail) {
      return true;
    } else {
      return false;
    }
  };  

Either way will work.

Sign up to request clarification or add additional context in comments.

7 Comments

I have tried with your code but filter is not working.
See the edit I just made. Update your select to the new one I just posted and modify your filter as suggested. That should do the trick.
See my latest edit. You might like the first option better now. Let me know if you have any questions Vimal!
Thank you nweg. A small correction, At the very first time getting empty. After changing the drop down working perfectly fine.
Vimal use my first example. That fixes the issue you are referring to. Just update your select ng-options expression to: deck as deck.name + ' - ' + deck.level for deck in data" and leave your filter as you originally had it.
|
0

This works for me:

    <div class="form-group">
        <label for="vehicle">Vehiculo:</label>
        <select ng-model="journeyEdit.vehicle" class="form-control" ng-options="vehicle as vehicle.Descripcion + ' - ' + vehicle.Patente for vehicle in vehicles track by vehicle.Id"  required>
            <option value="">Seleccione una opcion</option>
        </select> 
    </div>

1 Comment

please post in English

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.