I have upgraded to Angular 1.2.9 from v 1.0.8 to help with the performance of my app.
I have introduced track by which has improved the speed.
What I used to have
<div class="result row"
data-ng-repeat="result in (filteredItems =
(results |
filter: filterPrice |
filter: filterCategories |
filter: filterTypes |
filter: filterAirConditioning |
filter: filterTransmission |
filter: filterFourByFour |
filter: filterFuelType |
filter: filterNumberOfDoors |
filter: filterOnAirport |
filter: filterFuelPolicy |
filter: filterUnlimitedMileage |
filter: filterFreeCancellation |
filter: filterTheftProtection |
filter: filterCDW |
filter: filterTaxesIncluded |
filter: filterProviders ) ) |
orderBy: [orderByOptions, orderByPriceLowToHigh, orderByPriority] |
limitTo: pageSize">
what I have now
<div class="result row"
data-ng-repeat="result in results |
filter: filterPrice |
filter: filterCarCategories |
filter: filterCarTypes |
filter: filterAirConditioning |
filter: filterTransmission |
filter: filterFourByFour |
filter: filterFuelType |
filter: filterNumberOfDoors |
filter: filterOnAirport |
filter: filterFuelPolicy |
filter: filterUnlimitedMileage |
filter: filterFreeCancellation |
filter: filterTheftProtection |
filter: filterCDW |
filter: filterTaxesIncluded |
filter: filterProviders |
orderBy: [orderByOptions, orderByPriceLowToHigh, orderByPriority] |
startFrom: currentPage*pageSize |
limitTo: pageSize track by $index">
I have pagination which looked for the length of filteredItems. That no longer exists. Also, some other JS needs the filteredItems for logging, analytics, etc
In the HTML view I can get the length of the ng-repeat after filters have been applied
{{(results |
filter: filterPrice |
filter: filterCarCategories |
filter: filterCarTypes |
filter: filterAirConditioning |
filter: filterTransmission |
filter: filterFourByFour |
filter: filterFuelType |
filter: filterNumberOfDoors |
filter: filterOnAirport |
filter: filterFuelPolicy |
filter: filterUnlimitedMileage |
filter: filterFreeCancellation |
filter: filterTheftProtection |
filter: filterCDW |
filter: filterTaxesIncluded |
filter: filterProviders)
.length}}
which is a bit of a mouthful but does return the number I want. How can I pass this to a $scope ?
You can create an intermediate variable that will hold the filtered array:
data-ng-repeat="result in filteredResults = (results | filter:filterPrice | filter:filterCarCategories | etc.)"
and then can use:
filteredResults.length
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With