2016-11-25 61 views
0

我想通过角度读取json的值并在UI上显示数据。我无法这样做,因为我得到的UI格式不是数组。当我添加到控制台并查看格式时,它有点不同。我试图在控制台上玩“c”,无法玩这个物体。如何在我的网页上显示{{详情}}的任何提示?angularjs从服务中获取正确的格式数据

enter image description here

<script> 
    var app = angular.module('myApp', []); 
    app.controller('myCtrl', function ($scope, $http, MyService) { 

      $scope.details = MyService.getDetails(); 
      console.log($scope.details); 

    }); 
    app.service('MyService', function ($http) { 
     this.getDetails = function (x, y) { 

      return $http.get("/Home/GetMyData") 
        .then(function (response) { 
         return response.data; 
        }); 
     } 
    }); 


</script> 

     public JsonResult GetMyData() 
     { 
      var details = GetDet(); 
      return Json(details, JsonRequestBehavior.AllowGet); 
     } 
+1

数组内名为“value”的对象内部是什么?属性?我的意思是,这些对象内的属性是什么? – lealceldeiro

+0

是的,我需要数据内的价值 – Kurkula

+0

你可以创建一个填充代码的小提琴吗? – Yaser

回答

1

MyService.getDetails返回一个承诺,所以下面只代码显示了承诺对象

$scope.details = MyService.getDetails(); 
console.log($scope.details); // promise object 

你需要这样做来获得getDetails的解析值:

MyService 
    .getDetails() 
    .then(function(details){ 
     $scope.details = details; 
     console.log($scope.details); // your array 
    }); 

我希望这有助于!