AngularJS 1.6.x:无法读取属性'条目'未定义的

时间:2017-05-13 22:40:15

标签: angularjs

Plunker:http://plnkr.co/edit/XH8EiFpw1eUVrRtoByeY?p=preview

从角度read property 'entry' of undefined升级到1.3.x

后,我不确定为什么错误显示1.6.x

我已经尝试过定义'条目'因为var entry = {};也试过依赖注入,但它仍然出错。

以下是代码:

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

app.controller('SuperCtrl', ['$scope', '$http', function($scope,$http) {
    var url = 'https://spreadsheets.google.com/feeds/list/1O7M5gaEGlyE5gkOBARJrxJJMBYiTwz2THVjgbaTx9v8/od6/public/values?alt=json';
    var parse = function(entry) {
      console.log(entry);
                var category = entry.gsx$category.$t;
                var description = entry.gsx$description.$t;
                var title = entry.gsx$title.$t;
      return {

        description: description,
        title: title
      };
    };
    $http.get(url)
    .then(function(response) {
      var entries = response.feed.entry;
      $scope.parsedEntries = [];
      for (var key in entries) {
        var content = entries[key];
        $scope.parsedEntries.push(parse(content));
      }
    });
}]);

1 个答案:

答案 0 :(得分:0)

在这部分代码中:

$http.get(url)
.then(function(response) {
  var entries = response.feed.entry;

  ...
});

您应该通过响应的data属性:

$http.get(url)
.then(function(response) {
  var entries = response.data.feed.entry;

  ...
});