P
P
Peter2016-03-05 22:54:39
Angular
Peter, 2016-03-05 22:54:39

Is it possible to show multiple elements according to filters in a view in angularjs?

Thanks to orderBy and filter, data in ng-repeat can be sorted and filtered right in the view.
I need to do scrolling (loading of 10 elements) along with sorting and filtering.
Is it possible to do so in the view, so that ng-repeat would give an array of 100 elements that were filtered and sorted, but 10 elements were shown from the beginning, and when the button is clicked, another 10, on the next click another 10, etc. ?
If yes, how to do it?
If not, then I will do it through the controller.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
rakro, 2016-03-05
@rakro

It is possible if you create a filter that will display a certain number of elements (n) and apply it after the filter and orderBy filters. And when you click on the "Load more" button, increase the number n by 10. But this is a so-so solution. Knowledgeable people, like Sergey Protko , advise not to use filters with ng-repeat, but to prepare a filtered and sorted array at least in the controller. That's what I would do.

L
lega, 2016-03-05
@lega

https://docs.angularjs.org/api/ng/filter/limitTo

V
Vladislav Yandimirkin, 2016-03-05
@vlaad360

jsfiddle.net/api/post/library/pure
Not mine, attribution link fdietz.github.io/recipes-with-angular-js/common-us...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question