如何只访问数据而不是整个http get响应?

时间:2016-02-19 12:15:54

标签: angularjs

app.controller('treeController',['$http','$scope','dataService',function($http,$scope,dataService){
var treedata_avm=$http.get('WS/tree').success(function(data){
    }); 
    console.log(treedata_avm);
    $scope.my_data = treedata_avm;
}]);

How do i get only the data instead of other attributes as shown?

2 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

app.controller('treeController',['$http','$scope','dataService',function($http,$scope,dataService){
     var treedata_avm;
     $http.get('WS/tree').success(function(response){
          treedata_avm = response.data;
          console.log(treedata_avm);
          $scope.my_data = treedata_avm;
     }); 
}]);

答案 1 :(得分:0)

你没有考虑Javascript中的异步编程。谷歌有很多优秀的资源,但这个例子应该是这样的:

app.controller('treeController', ['$http', '$scope', 'dataService', function($http, $scope, dataService) {
  $http.get('WS/tree').success(function(data) {
    $scope.my_data = data;
  });
}]);