0

I have a standard ng-repeat

<tr ng-repeat="tran in filteredTransactions(history)">

$scope.history is doing a call to a factory to get a json result back

$scope.history = historyFactory.getHistory;

I have created another scope object to compare items from an array and filter the $scope.history to build the 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 a list of 'buttons' that users will be able to click to engage that item in the filter. For instance if they click 'Item 1' I would like that to be added to the array and the ng-repeat filtered accordingly.

I have an ng-click function that is pushing/popping the items out of the array correctly. However the ng-repeat isn't updating. Is there a better way to get this to work?

1 Answer 1

1

Rather then try and return a list of filtered items use the filter and put your filter function there.

       <tr ng-repeat="tran in history | filter: filteredTransactions(tran)">

        $scope.filteredTransactions = function (item) {
         if ($scope.filterBy.length > 1) {
            // check criteria and return either true or false
         } else {
           return true;
         }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.