TietjeDK TietjeDK - 1 year ago 80
AngularJS Question

Angular ng-repeat not detecting changes

I'm using

to iterate over a json response via
. Inside the
callback i run a for-loop to create a new array which should be handled by another


method: "GET",
url: "xxx",
headers: {
"Accept": "application/json;odata=verbose"
}).success(function (data, status, headers, config) {

$scope.onboardings = data.d.results;
var counter = {};

for (var i = 0; i < $scope.onboardings.length; i += 1) {
counter[$scope.onboardings[i].Company] = (counter[$scope.onboardings[i].Company] || 0) + 1;

$scope.onboardingCompanies = counter;


<div ng-repeat="item in onboardingCompanies">

So I need the ng-repeat to detect changes in
. I know there is some async trouble here.


Object {Monjasa A/S (FRC): 35, C-bed BV: 2, Monjasa DMCC: 1, Monjasa Pte: 4, Monjasa SA: 9…}

Any advice?

Answer Source

Your HTML is wrong: Angular doesn't give you an object with key and value attributes, it gives you them separately:

<div ng-repeat="(key,value) in onboardingCompanies">

The form you used ng-repeat="item in onboardingCompanies" angular will attempt to iterate over an array, but as the object isn't an array the result will be empty.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download