json中的键值不能以角度形式访问

时间:2016-01-13 09:02:34

标签: angularjs json

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

app.directive('myGridTable', function($http) {
  return {
    restrict: 'AE',
    link: function(scope, element, attrib) {
      $http.get(attrib.src).success(function(response) {
        scope.rows = response.data;
      });
      console.log("message from directive");
      angular.forEach(scope.rows, function(value, key) {
        console.log(key);
      });
    }
  };
});

1 个答案:

答案 0 :(得分:2)

您正在回访之外访问回复。

让你的循环成功。

试试这个

$http.get(attrib.src).success(function(response) {
    scope.rows = response.data;
    console.log("message from directive");
    angular.forEach(scope.rows, function(value, key) {
        console.log(key);
    });
});