0

I have the following code:

<select name="condition"
    ng-options="operation.id  as operation.description for operation in Operators  | myfilter:criterion_id" > 
</select>

and

module.filter('myfilter', function () {
  return function (x) {
    return  ?????
  };
});

I want to populate my select list with those options whose operation.id equals criterion_id. How may I achieve that?

0

3 Answers 3

2

You don't need to make your own filter, Angular's default filter will work:

<select name="condition"
    ng-options="operation.id  as operation.description for operation in Operators | filter:{id:criterion_id}" > 
</select>
Sign up to request clarification or add additional context in comments.

Comments

1

You should filter your array based on a condition and return the filtered array.

module.filter('myfilter', function () {
  return function (arrayOptions, criterion_id) {
    var result = [];
    result = arrayOptions.filter(function(operation){
        return (operation.id == criterion_id);
    })
    return result;
  };
});

But you should do this in case of a complex filtering process with data manipulation, otherwise you should use filter filter from Angular.

Operators  | filter: {id: criterion_id}

Comments

0

I've just written some code here.. please check it: http://jsfiddle.net/k86sy0ku/1/

    <select 
        ng-options="p as p.first for p in people |  filter:{id:FilterId}"
        ng-model="selectedPerson"></select>

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.