question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filters ng-repeat not working inside vs-repeat

See original GitHub issue

Kamilkp, thanks for this great directive. I was just wondering if it’s possible to use filter(s) inside your vs-repeat directive?

I tried the example below, but the provided default, custom filters dont filter anything. When used without your directive it works fine.

<ul vs-repeat="120" vs-offset-after="6" class="repeater-container">
    <li ng-repeat="item in items | filter:MyFilter | filter:query">
        {{item.name}}
        ...
        ...
    </li>
</ul>

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
kamilkpcommented, Jul 14, 2014

That’s entirely not the fault of vs-repeat. The problem is that vs-repeat creates new non-isolated scope. And if you write:

<div ng-repeat="item in filtered = (items | filter:MyFilter | filter:query )">

you basically write to a filtered variable on the current scope. If you wrap it with vs-repeat the filtered variable gets written into vs-repeat’s scope not the outer scope. Writing like that:

<div ng-repeat="item in filtered.result = (items | filter:MyFilter | filter:query )">

should fix the issue. Chceck out the updated gist: https://gist.github.com/kamilkp/40332795f8cf256772ce/revisions

I didn’t test it but i’m pretty sure it will work like that.

0reactions
tcdevscommented, Jul 14, 2014

I did test it and you are once again correct. Nice trick to use the ng-init attribute! That’s one of the ng-attributes i never actually use, but in this case its handy.

Thanks again for the quick help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter not working in ng-repeat - Stack Overflow
A filter on ng-repeat will only take into account what is in the object. Not what might be displayed while the loop is...
Read more >
Be careful when using ng-repeat's $index - CodeUtopia
AngularJS best practices: Be careful when using ng-repeat's $index · A simple list with an action · Adding a filter · Using $index...
Read more >
Angular-JS ng-repeat Directive - GeeksforGeeks
Angular-JS ng-repeat directive is a handy tool to repeat a set of HTML code for a number of times or once per item...
Read more >
Dynamic filter within ng-repeat in AngularJS - iTecNote
For my AngularJS app I have an ng-repeat in an ng-repeat like so: Html: <div ng-app="myApp"> <div ng-controller="myController"> <h2>working filter</h2> <div ...
Read more >
AngularJS to Angular concepts: Quick reference
The *ngFor directive in Angular is like the ng-repeat directive in AngularJS. It repeats the associated DOM element for each item in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found