0

I have an API returning the following simple JSON array:

[
  "efd98ad-first_key",
  "100eb0a-second_key"
]

I am trying to render this as a table with Angular:

<div name="listkeys" class="container">
  <div class="starter-template">
    <div ng-bind-html="message"></div>
    <table class="table table-striped table-bordered table-condensed sortable" ng-init="getKeys()">
      <tr>
        <th>bucket</th>
      </tr>
      <tr ng-repeat="bucket in buckets">
        <td>{{bucket}}</td>
      </tr>
    </table>
  </div>
</div>

JS:

var app = angular.module('flipDaSwitch', ['ngSanitize']);

app.controller('ListKeys', function($scope, $http) {

  $scope.getKeys = function() {
    $http.get('/api/keys').
      success(function (data) {
        $scope.response = data;
      }).
      error(function (data){
        $scope.response = {}
      });
  };

});

It does not do anything but throwing an "Uncaught object" error and that is it.

How could I debug why it is failing?

2
  • The answers are right, but Uncaught Object is thrown because one of your module dependencies is not met. Are you importing the angular-sanitize.js file? Commented Jun 5, 2014 at 22:17
  • @Mike thanks for the answer this was the last item before my little homepage started to work. Thanks!! Commented Jun 5, 2014 at 22:20

2 Answers 2

1

You are storing the values in $scope.response, but you are using $scope.bucket at the ng-repeat:

$scope.getKeys = function() {
$http.get('/api/keys').
  success(function (data) {
    $scope.buckets= data;
  }).
  error(function (data){
    $scope.buckets= {}
  });

};

Sign up to request clarification or add additional context in comments.

Comments

0

It looks like you do not have a scope item called buckets. I'd expect to see:

$scope.buckets = data

Inside the success callback.

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.