ng-repeat declared variable not getting updated in controller

371 Views Asked by At

I have declared a $scope variable in my controller:

$scope.filteredPayments = [];

I have an ng-repeat in my HTML that runs the following:

ng-repeat="payment in filteredPayments = payments"

payments is populated asynch from Parse. It works correctly and populates my table accordingly.

The following watch does not fire either:

$scope.$watch('filteredPayments', function(newValues) {
    console.log(newValues);
}

Why is filteredPayments not being updated in my controller especially since when I have no filters defined it shows all of the payments I have in my backend?

1

There are 1 best solutions below

6
On

It looks like you are trying to bind payments to filter payments in the ng-repeat like

filteredPayments = payments

What you should do is update the $scope.filteredPayments, as that is what the repeat is being run upon. So maybe a $q promise from your parse (or whatever you prefer) and then set. Something along the lines of this (again I don't know exactly how you get your data back.

 //retrieve new data

 .then(function(newData){

  $scope.filteredPayments = newData;
  });

Or maybe something simple, as long as you are sure the payments variable is updated like :

$scope.filteredPayments = payments;