1

Using AngularJS. I have a table on my HTML page for which the rows are populated from an array of objects in the $scope using ng-repeat with a filter. The filter is populated from an input box above the table.

If I want to add a button or some other UI object to the page that when clicked will perform some operation on the array of objects that are selected as a result of the filter, how can I obtain access to the filtered array from the javascript code in my controller? Is there a way to apply the user-supplied filter to the array or to iterate over the filtered array?

Thanks for any suggestions.

1 Answer 1

1

You can use the $filter function directly in JavaScript inside the button click handler as such:

$filter('filter')(array, expression, comparator)

See AngularJS documentation on $filter (In JavaScript section) for more details.

Here's another similar question: Accessing ng-repeat filtered data

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

1 Comment

Thanks, Sid. That worked perfectly. Sorry I missed the similar question in my search.

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.