[Chartjs]-Load JSON to display data, using ng-repeat {ANGULAR.JS}

5👍

The problem with your code is that json is Promise object not the data returned from AJAX call. Also your question has “returning from AJAX request” aspect. Make sure you understand related problem, check this very popular question.

Proper way to set scope data retrieved with AJAX request in Angular is to do it inside then callback:

app.controller('jsonServerBox', function ($scope, $http) {
    $http.get('serverbox.json').then(function (res) {
        $scope.ocw = res.data;
    });
});

4👍

In you case json variable is nothing but it contains promise object.

And Promise should always be resolve using .then

CODE

var json = $http.get('serverbox.json').then(function(res) {
    return res.data;
});
json.then(
  //success callback
  function(data) {
      $scope.ocw = data
  },
  //error callback
  function() {
      //error handling
  })
});

This would help you.

Thanks.

Leave a comment