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
The solution is ng-bind-template, it can bind more than one {{}} expression, so it can show more than a single value that was declared in the Script function.
AngularJS ng-options Directive The ng-options directive fills a <select> element with <options>. The ng-options directive uses an array to fill the dropdown list. In many cases it would be easier to use the ng-repeat directive, but you have more flexibility when using the ng-options directive.
Use ng-init to set default value for ng-options . Save this answer. Show activity on this post. In my opinion the correct way to set a default value is to simply pre-fill your ng-model property with the value selected from your ng-options , angular does the rest.
The select directive is used together with ngModel to provide data-binding between the scope and the <select> control (including setting default values). It also handles dynamic <option> elements, which can be added using the ngRepeat or ngOptions directives.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With