1

I have scope array property. I'm filling in the data by calling ajax service. What is happening is that even the data is populated in the array as expected I need to focus some other control or click somewhere on the page in order to display the array.

This is the array I have:

<ul class="list-group">
  <li class="list-group-item" ng-repeat="address in proposaladdresses">
    {{address.FormattedAddress}}
    <input type="button" ng-click="SubmitAddress(address.RefId, $parent.$index)" class="btn btn-success btn-sm pull-right" value="Select"/>
  </li>
</ul>

Array is populated this way:

$scope.proposaladdresses = [];
$.ajax({
  url: url,
  dataType: "jsonp",
  data: {
    "key": 'dasdasdas',
    "AddressLine": $scope.CustomAddress,
  },
  success: function (data) {
    if (data) {
      $scope.proposaladdresses = data;
    }
  },
});

Any idea why I need to do one more extra step in order to see the data on the screen?

3
  • 2
    change to angular $http instead of ajax call Commented Feb 14, 2017 at 9:30
  • I think you have the problem with a data binding. Maybe $scope.$apply method called after $.ajax.success will fix this problem. Ofcourse it's better to use $http instead of jQuery $.ajax Commented Feb 14, 2017 at 9:32
  • show data array. Commented Feb 14, 2017 at 9:35

1 Answer 1

1

Try calling

 if (data) {
  $scope.proposaladdresses = data;
  $scope.$apply();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.