javascript - Unable to show filtered item after using limitTo along with ng-show and ng-repeat -
i have array of famous places
, each place contains tour
array 20 elements 20 number of tours under each famous places. e.g. 'egypt' contains 20 tours in attractive locations. problem tours not contain hotels, tours have hotels. here code.
<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 1st ng-repeat
have shown tour containing hotel(number of hotel 1) using ng-show
. in 2nd ng-repeat
have displayed hotel names hotels
array.
ultimately, have extracted hotel names tours contain hotel using two ng-repeat
.
everything working fine, want show first 3 hotel names hotel-list got 2nd ng-repeat
. adding limitto:3
in 1st ng-repeat
not showing 1st 3 hotel name, because 1st 3 elements hidden there no hotel, there indexes remains ! .
i found similar topic ,but unable using ng-repeat , limitto limit number of visible items displayed
how can show 1st 3 hotel name filtered hotel list? or doing wrong?
use filter tour in tours | filter: { hotels: []} | limitto:3
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>example - example-filter-filter-production</title> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> </head> <body ng-app=""> <div ng-init="tours = [ {name:'a', hotels : [ {name:'aa'},{name:'ab' }] , }, {name:'b', hotels : [ {name:'aa'},{name:'ab' }] , }, {name:'d', hotels : [ {name:'aa'}] }, {name:'e', hotels : [ {name:'aa'},{name:'ab' }] , }, {name:'f', hotels : [ {name:'aa'},{name:'ab' }] , }, {name:'g', hotels : [ {name:'aa'},{name:'ab' }] , }, {name:'nonea', }, {name:'noneb', } ] "></div> <div ng-repeat="tour in tours | filter: { hotels: []}"> tour name : {{tour.name}} {{tour.hotels.length}} <br> <div ng-repeat="hotel in tour.hotels"> hotel name : {{hotel.name}} <br/> </div> <br> </div> </html>
Comments
Post a Comment