Search code examples
angularjsangularjs-ng-repeatangularjs-filterangularjs-limitto

AngularJS ng-repeat filter to apply if condition is met


I have two arrays. One is items and the other is items2.

And if items2 is an empty array I only want to show the one item in items. How can apply a condition to the filter limitTo?

The limitTo should only be considered if a certain condition is met.

Thank you!


Solution

  • Ternary expression will help you!

    Example: limitTo : !items2.length ? 1 : n