2017-02-21 17 views
0

私はSpringブートに基づいてフロントエンドにデータを提供するバックエンドを実装しました。それはうまく動作します。 http://localhost:4983/employee/ALL/AngularJS httpsが応答しますが、表示されませんでした

応答::私はローカルホストを参照するためにクロムを使用する場合、それは URL作品

'[{"id":1,"name":"ALFRED","dept":"871m","email":"[email protected]","salary":120000}, 
{"id":2,"name":"FRANK","dept":"TCTO","email":"[email protected]","salary":920000}, 
{"id":3,"name":"NANCY","dept":"TDSB","email":"[email protected]","salary":620000}, 
{"id":4,"name":"TONG","dept":"NYGH","email":"[email protected]","salary":720000}, 
{"id":5,"name":"CINDY","dept":"University Of Victoria","email":"[email protected]","salary":9987654}, 
{"id":6,"name":"CINDY HUANG","dept":"University Of Victoria","email":"[email protected]","salary":9987654}]' 

をしかし、私は$ HTTPにHTMLや角度JSを使用する場合、予想通り、データは表示されませんでした。ここで

私の角度JSコードです:

<html> 
 
<head> 
 
    <title>Angular JS Includes</title> 
 
    <style> 
 
     table, th, td { 
 
      border: 1px solid grey; 
 
      border-collapse: collapse; 
 
      padding: 5px; 
 
     } 
 
     table tr:nth-child(odd) { 
 
      background-color: #f2f2f2; 
 
     } 
 
     table tr:nth-child(even) { 
 
      background-color: #ffffff; 
 
     } 
 
</style> 
 
</head> 
 
<body> 
 
    <script> 
 
     function employeeController($scope, $http) { 
 
      $http({method: 'GET', url: 'http://localhost:4983/employee/ALL/'}) 
 
\t \t .success(function (response) { 
 
     \t \t $scope.employees = response; 
 
console.log($scope.employees); 
 
$scope.context = "IT works"; 
 
\t \t }); 
 
     } 
 
    </script> 
 

 
    <h2>AngularJS Employee Application</h2> 
 
    <div ng-app="" ng-controller="employeeController"> 
 
{{ context }} 
 
{{ employees[0].id }} 
 
     <table> 
 
      <tr> 
 
       <th>Employee ID</th> 
 
       <th>Employee Name</th> 
 
       <th>Employee Dept</th> 
 
       <th>employee Email</th> 
 
\t \t <th>employee Salary</th> 
 
\t \t <th>{{ msg }}</th> 
 
      </tr> 
 
      <tr ng-repeat="empl in employees"> 
 
       <td>{{ empl.id }}</td> 
 
       <td>{{ empl.name }}</td> 
 
      <td>{{ empl.dept }}</td> 
 
       <td>{{ empl.email }}</td> 
 
      <td>{{ empl.salary }}</td> 
 
\t \t <td>{{ msg }}</td> 
 
      </tr> 
 
     </table> 
 
    </div> 
 
{{ msg }} 
 

 
<script src='http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js'></script> 
 
</body> 
 
</html>

私はChromeで、このページを参照すると、私はバックエンドスプリングブートと呼ばれるデータで応答してきた見ることができます。しかし、フロントエンドはそれを表示しません。誰かが私が間違ったことを見ることができますか? {|オブジェクト列} - - 変換関数を用いて形質転換応答本体

データ:

+0

ここでモジュールを定義しましたか? –

+0

ブラウザのコンソールでエラーをチェックしましたか?またはログの値? –

答えて

0

https://docs.angularjs.org/api/ng/service/$httpからの応答オブジェクトは、これらの特性を有しています。 status - {number} - 応答のHTTPステータスコード。 headers - {function([headerName])} - ヘッダーゲッター関数。 config - {Object} - 要求を生成するために使用された構成オブジェクト。 statusText - {string} - レスポンスのHTTPステータステキスト。

この場合は、次のようにします。$ scope.employees = response.data;

0
$ HTTPサービスのドキュメントを参照手始めに

、:

$ HTTPレガシー約束方法successerrorが廃止されました。代わりに標準thenメソッドを使用してください。

function employeeController($scope, $http) { 
    $http({ 
    method: 'GET', 
    url: 'http://localhost:4983/employee/ALL/' 
    }).then(function (response) { 
     $scope.employees = response; 
     console.log($scope.employees); //check what this outputs 
     $scope.context = "IT works"; 
    }); 
} 

にコードを変更してみてください。またきっとあなたは私たちにローカルホストのURLを与えることが、ここで任意の使用であることを行っていない、実現しています。

さらに、コードに多くの問題がある可能性があります。ブラウザのコンソールでエラーがないかどうかを確認したり、コンソールで出力がconsole.log($scope.employees)であるかを少なくとも確認してください。

関連する問題