I have a collection of well-known locations
, each location includes a tour
array with 20 elements - representing the number of tours available at that particular location. For example, 'Egypt' has 20 tours showcasing its various attractions. However, some tours do not include any accommodation options, while others do.
<div ng-repeat="tour in place.tours | limitTo:3" ng-show="tour.hotels.length != 0">
<li>
<a ng-repeat="hName in tour.hotels"> {{hName.name}}
</a>
</li>
</div>
In the first ng-repeat
, I only display tours that have a hotel available (with 1 hotel) using ng-show
. In the second ng-repeat
, I list out the names of hotels from the hotels
array.
Ultimately, I extract all hotel names from tours that offer accommodations by using these two ng-repeat
.
While everything is functioning as intended, I now want to display only the first 3 hotel names from the list obtained in the second ng-repeat
. Adding limitTo:3
in the first ng-repeat
does not show the first 3 hotel names because those elements are already hidden if no hotel is present, although the indexes persist!
I came across a related discussion on this topic but it didn't provide a solution Using ng-repeat and limitTo to limit the number of visible items displayed
How can I specifically showcase only the first 3 hotel names from the filtered list of hotels? What am I overlooking in my approach?