I have an ng-repeat that isn\'t updating upon changing the data in the array that it is using. I\'ve researched for quite a while but nothing seems to be working. Initiall
The problem is that ng-repeat has referenced on this initial empty array []
, when you change $scope.getBusinessSites
, you change this variable's reference, but ng-repeat still reference on that empty array in memory.
So, solution is write data directly to array your ng-repeat reference. You can do it with angular.extend function:
Change this line:
$scope.getBusinessSites = response.data;
On this one:
angular.extend($scope.getBusinessSites, response.data);
// empties an array
$scope.getBusinessSites.length = 0;
The ng-repeat create its own scope. Try adding $parent
to reference your variable on your current controller scope
Try wrapping the tbody inside of a div and but the controller in the div:
<div ng-controller="BusinessController">
<tbody>
<tr ng-repeat="site in getBusinessSites">
.
.
.
</tbody>
</div>
and I suggest naming the $scope.getBusinessSites to $scope.businessSites for avoiding confusion :)