0

I'm new to angularJs. I'm facing an issue where i need to filter an array (in ng-repeat) by finding the element in array.

<div class="row" ng-repeat="(class_list_key, class_list) in trialList | filter: {class_id:selected_class_option_arr}">

I tried the above code (which is wrong). Here selected_class_option_arr is an array having values by which i need to filter trialList array using class_id.

Array selected_class_option_arr is like this -

["Sat_09:00_AM_10:30_AM", "Fri_10:00_AM_11:00_AM"]

I tried to find but didn't got proper example as per my requirement.

1 Answer 1

1

Provide a filter function in the ng-repeat and loop through the against array to filter out the required values:

<div class="row" ng-repeat="classList in trialList | filter: filterClass >

In the controller:

$scope.filterClass = function(classList) {
      for(var i=0; i < selected_class_option_arr.length; i++) {
          return classList.class_id.indexOf(selected_class_option_arr[i]) != -1 
     }  
};

Working Plunker: https://plnkr.co/edit/yQ7D9fwwitfMktOkGjF8?p=preview

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

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.