0

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!

N.Car
  • 492
  • 1
  • 4
  • 14

2 Answers2

3

Ternary expression will help you!

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

Fleeck
  • 1,036
  • 2
  • 8
  • 21
1

You can manage the condition in a function:

$scope.getItems() {
     return items2.length === 0 ? [items[0]] : items;
}

<div ng-repeat="item in getItems()"> {{ item.x }}</div>
Faly
  • 13,291
  • 2
  • 19
  • 37