angularjs - ng-repeat filtering based on array -
i have standard ng-repeat
<tr ng-repeat="tran in filteredtransactions(history)">   $scope.history doing call factory json result back
$scope.history = historyfactory.gethistory;   i have created scope object compare items array , filter $scope.history build ng-repeat
$scope.filteredtransactions = function () {     if ($scope.filterby.length > 1) {         return $scope.history.filter(function (tran) {             return $scope.filterby.indexof(tran.slot) !== -1;         });     }     else {         return $scope.history;     } }   i have list of 'buttons' users able click engage item in filter. instance if click 'item 1' added array , ng-repeat filtered accordingly.
i have ng-click function pushing/popping items out of array correctly. ng-repeat isn't updating. there better way work?
rather try , return list of filtered items use filter , put filter function there.
       <tr ng-repeat="tran in history | filter: filteredtransactions(tran)">          $scope.filteredtransactions = function (item) {          if ($scope.filterby.length > 1) {             // check criteria , return either true or false          } else {            return true;          }      
Comments
Post a Comment