0

I'm pretty new to angular. I want to have a where clause in my ng-options like this :

select * from currencies where  currency.code in ( 'usd' , 'cad')

<select ng-model="selectedCurrency" ng-options="currency.Name for currency in Currencies | filter:currency.code = 'usd' track by currency.ID">
    <option value="">-- select a currency--</option>
</select>

I could do it for only one code but I want to select it from an array of two or more !

3
  • 1
    please show your code Commented Nov 1, 2016 at 14:31
  • I want to filter by two currencies : USD and CAD Commented Nov 1, 2016 at 14:33
  • Read the documentation of the filter filter. It accepts a predicate function as argument. Implement a function that returns true if the currency code is one of the accpted ones, and pass that function to the filter. Commented Nov 1, 2016 at 14:36

2 Answers 2

2

Try with:

ng-options="currency.Name for currency in Currencies track by currency.ID | filter: {code: 'usd'}"

To search multiple values you can use a function:

$scope.filterCurrencyCodes = function(currency) {
    return (['usd', 'cad'].indexOf(currency.code) !== -1);
};

ng-options="currency.Name for currency in Currencies track by currency.ID | filter: filterCurrencyCodes"
Sign up to request clarification or add additional context in comments.

Comments

0

Try with:

ng-options="currency.Name for currency in Currencies track by currency.ID | filter: filterCurrency"

And then create a method for evaluate the currency code:

$scope.filterCurrency= function(currency){
   if(currency.code == 'USD' || currency.code == 'CAD'){
       return true;
   }
   return false;
};

Comments

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.