0

JS:

function ctrlr($scope, $http) {
    $http.post(urlhere).success(function(data) {
        $scope.Items = data;
    });
}

HTML:

<body ng-app="">
    <div ng-controller="ctrlr">
        <div ng-repeat="item in Items">
           {{ item.Name }}
        </div>
    </div>
</body>

Data returned from post request is a list of a class object (that contains Name property)

Checked, data is not empty. It returns an xml formatted response.

Why won't my ng-repeat work? Tried using jquery ajax, which returned json but still no go

Duyen-Hoa
  • 15,384
  • 5
  • 35
  • 44
Sharon Dorot
  • 542
  • 1
  • 4
  • 15

2 Answers2

0

If you're running ng-repeat on a js object instead of array you should do something like this

<div ng-repeat="(key, val) in Items">
  <span>{{key}}</span>
  <span>{{val}}</span>

khizar naeem
  • 296
  • 2
  • 6
0

Well it may sound silly but the problem was that $scope.Items is being initialized in the success, an async method so it was undefined when it arrived to ng-repeat.

I solved it by switching to jquery ajax and adding async: false

Sharon Dorot
  • 542
  • 1
  • 4
  • 15
  • That's not how angular is supposed to work. There was certainly another issue that you've bypassed. I suggest you to read this : http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background – Deblaton Jean-Philippe Feb 25 '15 at 14:20
  • Furthermore, making synchronous calls from your client will really lower the performances of your application. – Deblaton Jean-Philippe Feb 25 '15 at 14:21