R
R
Ramil Z.2016-01-09 00:04:58
Angular
Ramil Z., 2016-01-09 00:04:58

How to count the number of filtered values ​​in Angular JS (filter)?

Hi everybody!
Please tell me about those who have experience in Angular JS.
The task is as follows: there is a search string for phrases and, accordingly, a list of phrases. It is necessary to count the number of found phrases and display them on the screen. For example: total - 10500, found - 399.

ng-repeat="item in main.keywords | keywordsFilter:keywordCtrl.filterModel1 | keywordsFilter:keywordCtrl.filterModel2 | keywordsFilter:keywordCtrl.filterModel3 | keywordsFilter:keywordCtrl.filterModel4 | limitTo: 300 | orderBy:'freq':true"

.filter('keywordsFilter', function () {
            return function (items, criterion) {
                return items.filter(function (element, index, array) {
                    var str = String(element.phrase);
                    if (str.indexOf(criterion) + 1) {
                        return true;
                    } else {
                        element.visible = false;
                    }
                });
            }
        })

<ul class="list-inline">
            <li>Всего фраз: {{main.keywords.length}}</li>
            <li>Найдено: {{ ??? }}</li>
        </ul>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2016-01-09
@proteye

do it in the directive, prepare the data in the controller and that's it. No need to try to make it obviously inconvenient and wrong (from an architectural point of view).

N
Nicholas, 2016-01-09
@healqq

You don't want to load all 10500 (and if there are 100500) values ​​to the front, do you? Do it on the back, and show only what you need.
PS
To get a model with filtered records, you can write something like this:

ng-repeat="item in main.filteredKeywords = (main.keywords | filter1| fliter2|....)"

R
Ramil Z., 2016-01-09
@proteye

Here is what I am trying to do.
The backend is made simple without the use of frameworks, purely for data loading.
Sources: https://github.com/proteye/keywords-grouper
An example can be found here: proteye.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question