2017-01-21 2 views
0

$ scope.greetingはnullです: [{ "ID":1、 "名前" これはデータである http://localhost:8081/PetStoreSpringRest/rest/empsgreeting.idがnullであるか、私はRESTfulなWebサービスをテストし、それはデータがある

: "created"、 "createdDate":1484969286677}

Google Chromeのデバッグを使用すると、応答の値がわかります。データ しかし、window.alert($ scope.greeting.id);私はgreeting.idにNULLがあり、$ scope.greeting.idである理由、それはIDがあり、この

のヌル

結果を表示{{greeting.idが}}

が あるIDは必ず

されていませんヌル

\t \t \t \t <!doctype html> 
 
\t \t \t \t <html ng-app="demo"> 
 
\t \t \t \t \t <head> 
 
\t \t \t \t \t \t <title>Hello AngularJS</title> 
 
\t \t \t \t \t \t <script src="libs/angular.js"></script> 
 
\t \t \t \t  
 
\t \t \t \t \t <script> 
 
\t \t \t \t \t /* 
 
\t \t \t \t \t {"id":60,"content":"Hello, World!"} 
 
\t \t \t \t \t http://localhost:8081/PetStoreSpringRest/rest/emps 
 
\t \t \t \t \t [{"id":1,"name":"Albert Lam","createdDate":1484969286677},{"id":2,"name":"John John","createdDate":1484969286677}] 
 
\t \t \t \t \t */ 
 
\t \t \t \t \t angular.module('demo', []) 
 
\t \t \t \t \t .controller('Hello', function($scope, $http) { 
 
\t \t \t \t \t  $http.get('http://localhost:8081/PetStoreSpringRest/rest/emps'). 
 
\t \t \t \t \t \t then(function(response) { 
 
\t \t \t \t \t \t  $scope.greeting = response.data; 
 
\t \t \t \t \t \t  window.alert($scope.greeting.id); 
 
\t \t \t \t \t \t }); 
 
\t \t \t \t \t }); 
 
\t \t \t \t \t </script> 
 
\t \t \t \t \t </head> 
 

 
\t \t \t \t \t <body> 
 
\t \t \t \t \t \t <div ng-controller="Hello"> 
 
\t \t \t \t \t \t \t <p>The ID is {{greeting.id}}</p> 
 
\t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t 
 
\t \t \t \t \t \t </div> 
 
\t \t \t \t \t </body> 
 
\t \t \t \t </html>

答えて

0

あなたは、配列を返すように見えるので、あなたは<p>The ID is {{greeting[0].id}}</p>

ような何かを行う必要があります
0

あなたの応答が..です

[{"id":1,"name":"Albert Lam","createdDate":1484969286677},{"id":2,"name":"John John","createdDate":1484969286677}] 

取得し、すべてのIDの

<div ng-controller="Hello"> 
<div ng-repeat="x in greeting"> 
<p>The ID is {{x .id}}</p> 
</div> 
</div> 

特定のIDについては

<div ng-controller="Hello"> 
<p>The ID is {{greeting[0].id}}</p> 

関連する問題