I'm having an issue filtering my result sets in an ng-repeat. The filter gets run on each iteration through the ng-repeat cycle (so if I have 10 dispatches returned by currentDispatch.dispatches
it will run 10 times). The first time though, runs
will only have 1 element. The next time through it will have 2, then 3, and so forth. What the results look like on my screen is....
[1],[1],[1,3],[1,3,4]
How can i make it so it only runs the filter once as it has all the elements to filter against? I need only the final result set, not a result of every iteration through.
my custom filter
angular.module('prototype').filter('dispatchedForMyEquipment', ['Config', function(Config){
return function(runs){
var result = []
var myEquipment = Config.getEquipment();
runs.forEach(function(run, index, array){
myEquipment.forEach(function(dispatchEquipment, index, array){
if (run.units.indexOf(dispatchEquipment)!= -1){
result.push(run);
return
}
});
})
return result
}
}])
my ng-repeat clause
<tr ng-repeat-start="dispatch in ($state.current.data.latest ?
(currentDispatch.dispatches | orderBy: '-time' | dispatchedForMyEquipment)
: (currentDispatch.dispatches | orderBy: '-time')) track by $index">
I will take the track by $index out once I fix the issue at hand.
Ng-repeat does watch for itself , maybe u are getting data through a ajax request. Having said that just mask your ng-repeat with ng-if with the condition that it has all 10 elements... A dirty way right.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.